环境
windows 10 21H1
sqlAnywhere 5.0
RazorSQL 6.3.23 可视化SQLAnywhere 工具
php 5.4 (SQLAnywhere-PHP-5.4_Windows 扩展,自行下载配置)
准备
打开 控制面板\所有控制面板项\管理工具\ODBC 数据源(64 位),或者是ODBC Data Sources (32-bit),根据数据库版本来选择。
配置好数据库(添加源,修改,指定特定数据库,根据业务场景配置)。
代码
我做的是数据mysql转换到 SQLanywhere的程序。
<?php set_time_limit(0); $dbc['dbhost']='127.0.0.1'; $dbc['dbname']='labman'; $dbc['dbuser']='root'; $dbc['dbpwd']='root'; include('mysql.class.php'); $sampleda_g = isset($_GET['sampleda'])?$_GET['sampleda']:'2009-03-19'; //$start = isset($_GET['start'])?$_GET['start']:'9470'; $indexid = isset($_GET['indexid'])?$_GET['indexid']:1; $db = new DB($dbc); // id>9470 是3000条 //$conn=odbc_connect('ipu','DBA','sql'); $infos = $db->fetch_all("select * from labmain where sampleda='$sampleda_g'"); if(count($infos)>0){ $conn=odbc_connect('ipu3000','DBA','sql'); } foreach($infos as $k=>$v){ $infos[$k]['sampletype'] = get_stype($v['sampletype']); $sampleno = $v['sampleno']; $sampleda = $v['sampleda']; $infos[$k]['detail'] = $db->fetch_all("select sampleda,sampleno,itemno,srcresult from labdetail where sampleda='$sampleda' and sampleno='$sampleno'"); foreach($infos[$k]['detail'] as $m=>$n){ $rresult = mAP_result($n['itemno'],$n['srcresult']); if($rresult !== false){ $infos[$k]['detailn'][$rresult[0]]['rid'] = $rresult[0]; $infos[$k]['detailn'][$rresult[0]]['rre'] = $rresult[1]; } } unset($infos[$k]['detail']); } //print_r($infos);exit; $dayindex = 1; foreach($infos as $k=>$row){ echo $row['id'].'-'; if($row['id']>8472){ $ipu_m['Instrument_ID'] = 'XT-2000iV^14454'; $ipu_m['Sequence_No'] = $indexid; $ipu_m['Sample_No'] = str_pad($row['sampleno'],15," ",STR_PAD_LEFT); $ipu_m['Seq_NO'] = $dayindex; $ipu_m['DDate'] = $row['ddate']; $ipu_m['TTime'] = $row['ttime']; $ipu_m['PatIEnt_ID'] = null; $ipu_m['Dinfo1'] = '0'; $ipu_m['Dinfo2'] = '1'; $ipu_m['Minfo1'] = '268435713'; $ipu_m['Minfo2'] = '100665856'; $ipu_m['Scatta_FLG'] = '196725'; $ipu_m['Delta_FLG'] = '0'; $ipu_m['Rack_NO'] = null; $ipu_m['Tube_POS'] = '0'; $ipu_m['Sample_INF'] = '1'; $ipu_m['Rack_INF'] = '0'; $ipu_m['Validate_FLG'] = '1'; $ipu_m['ID_INF'] = '65'; $ipu_m['Hpc_COMM1'] = null; $ipu_m['HPC_COMM2'] = null; $ipu_m['OderInf'] = '5'; $ipu_m['Shift'] = ''; $ipu_m['AnimalSpecies'] = $row['sampletype']; $ipu_m['Category'] = '0'; $ipu_m['Sex'] = '1'; $ipu_m['Age'] = null; $ipu_m['AgeUnit'] = null; $ipu_m['ManualAna'] = '0'; $ipu_m['ManualExtAna'] = '0'; $ipu_m['ExtProfile'] = '0'; $ipu_m['FlaggingAna'] = '0'; $ipu_m['Ref_Sequence_No'] = $indexid; $ipu_m['ADate'] = null; $ipu_m['ATime'] = null; $ipu_m['AnaProfile'] = '0'; $ipu_m['User_ID'] = '5'; //echo $db->sql_array_value($ipu_m);exit; $sql = "INSERT INTO SAMPLE_TBL(Instrument_ID, Sequence_No, Sample_No, Seq_NO, DDate, TTime, Patient_ID, Dinfo1, Dinfo2, Minfo1, Minfo2, Scatta_FLG, Delta_FLG, Rack_NO, Tube_POS, Sample_INF, Rack_INF, Validate_FLG, ID_INF, HPC_COMM1, HPC_COMM2, OderInf, Shift, AnimalSpecies, CateGory, Sex, Age, AgeUnit, ManualAna, ManualExtAna, ExtProfile, FlaggingAna, Ref_Sequence_No, ADate, ATime, AnaProfile, User_ID) VALUES (".$db->sql_array_value($ipu_m).")"; $rs=odbc_exec($conn,$sql); if($rs){//插入成功,插入项目数据 for($i=0;$i<=130;$i++){ if(isset($row['detailn'][$i])){ $sql2 = "INSERT INTO DATA_TBL(Instrument_ID, Sequence_No, Test_CD, Data, Flag) VALUES ('XT-2000iV^14454', ".$indexid.", ".$i.", ".$row['detailn'][$i]['rre'].", 1);"; }else{ $sql2 = "INSERT INTO DATA_TBL(Instrument_ID, Sequence_No, Test_CD, Data, Flag) VALUES ('XT-2000iV^14454', ".$indexid.", ".$i.", 0, 1);"; } $rs2=odbc_exec($conn,$sql2); if($rs2){ echo "<pre>".$indexid."-1&2</pre>\n"; }else{ echo "<pre>".$indexid."-1</pre>\n"; } } }else{ echo "<pre>f:".$indexid."</pre>\n"; } $indexid++; $dayindex++; } } $newday = date("Y-m-d",strtotime("+1 day",strtotime($sampleda_g))); nexturl("insert3000.php?sampleda=".$newday."&indexid=".$indexid); function get_stype($stid){ $ana_dict_t = array( 1=>'大鼠', 2=>'小鼠', 3=>'狗', 4=>'猴', 5=>'猫', 6=>'豚鼠', 7=>'马', 8=>'兔', 9=>'猪', ); $ana_dict = array( 1=>2, 2=>1, 3=>4, 4=>5, 5=>14, 6=>15, 7=>13, 8=>3, 9=>7, ); if(isset($ana_dict[$stid])){ return $ana_dict[$stid]; }else{ return 7;//other } } function map_result($itemno,$result){ $map = array( 'WBC'=>array(0,$result*100), 'RBC'=>array(1,$result*100), 'HGB'=>array(2,$result), 'HCT'=>array(3,$result*10), 'MCV'=>array(4,$result*10), 'MCH'=>array(5,$result*10), 'MCHC'=>array(6,$result), 'PLT'=>array(7,$result), 'RDW-SD'=>array(8,$result*10), 'RDW-CV'=>array(9,$result*10), 'PDW'=>array(10,$result*10), 'MPV'=>array(11,$result*10), 'P-LCR'=>array(12,$result*10), 'PCT'=>array(13,$result*100), 'NEUT#'=>array(20,$result*100), 'LYMPH#'=>array(21,$result*100), 'MONO#'=>array(22,$result*100), 'EO#'=>array(23,$result*100), 'BASO#'=>array(24,$result*100), 'NEUT%'=>array(25,$result*10), 'LYMPH%'=>array(26,$result*10), 'MONO%'=>array(27,$result*10), 'EO%'=>array(28,$result*10), 'BASO%'=>array(29,$result*10), 'RET%'=>array(53,$result*100), 'RET#'=>array(52,$result*10), 'IRF'=>array(57,$result*10), 'LFR'=>array(56,$result*10), 'MFR'=>array(55,$result*10), 'HFR'=>array(54,$result*10), ); if($itemno=='NRBC#' || $itemno=='NRBC%'){ return false; } if(isset($map[$itemno]) || $itemno=='NRBC#' || $itemno='NRBC%'){ return $map[$itemno]; }else{ echo $itemno; print_r($map); exit(' debuging....map'); } } function nexturl($url){ echo '<script language="javascript"> function redirect(url) { window.location.replace(url); } </script>'; echo "<script>setTimeout(\"redirect('$url');\", 300);</script>"; echo "<br>如果浏览器没有跳转,<a href=\"$url\">点击这里</a><br />"; exit; }
添加新评论