1. 程式人生 > >php 連接oracle插入多張圖片的方法

php 連接oracle插入多張圖片的方法

stat name tran eat def 錯誤 scrip res nec

  php連接oracle數據庫的時候,其查詢、更新、刪除數據和MySQL類似,但是增加數據、特別是圖片的時候就很不一樣,這裏面涉及到要創建一個blob對象,用blod對象去保存php圖片,下面是當插入多張圖片的時候的寫法,直接上代碼:

$conn = oci_connect(‘RGSUser‘, ‘mycompany‘, ‘(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = **.**.**.**(IP地址))(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl)))‘, ‘utf8‘);

 
$sql = $sql."ID,"; $value = $value."sys_guid(),"; $sql = $sql."LSH,"; $value = $value.":lsh".","; $sql = $sql."VERFYTYPE,"; $value = $value.":verfytype".","; $sql = $sql."IDENTIFICATIONNO,"; $value = $value.":id".","; $sql = $sql."REALNAME,"; $value = $value.":realname".","; $sql = $sql."PHONE,"; $value
= $value.":phone".","; $sql = $sql."BINDDRIVELICENSE,"; if ($dabh!=null) { $value = $value."1,"; }else{ $value = $value."0,";} $sql = $sql."PICDATAIDENTIFACE,"; $value = $value."EMPTY_BLOB(),"; $sql = $sql."PICDATAIDENTIFACEWATERMARK,"; $value = $value."EMPTY_BLOB(),"; $sql = $sql."PICDATAIDENTIBACK,"; $value
= $value."EMPTY_BLOB(),"; $sql = $sql."PICDATAIDENTIBACKWATERMARK,"; $value = $value."EMPTY_BLOB(),"; $sql = $sql."PICDATAIDENTIPERSON,"; $value = $value."EMPTY_BLOB(),"; $sql = $sql."PICDATAIDENTIPERSONWATERMARK,"; $value = $value."EMPTY_BLOB(),"; $sql = $sql."ISLOCK) VALUES ("; $value = $value."0".")"; //這裏很重要,相當於保存圖片的字段指定了對應的標簽 $sql = $sql.$value." RETURNING PICDATAIDENTIFACE,PICDATAIDENTIFACEWATERMARK,PICDATAIDENTIBACK,PICDATAIDENTIBACKWATERMARK,PICDATAIDENTIPERSON,PICDATAIDENTIPERSONWATERMARK,PICDATAVEHICLELIC,PICDATAVEHICLELICWATERMARK INTO :PICDATAIDENTIFACE,:PICDATAIDENTIFACEWATERMARK,:PICDATAIDENTIBACK,:PICDATAIDENTIBACKWATERMARK,:PICDATAIDENTIPERSON,:PICDATAIDENTIPERSONWATERMARK,:PICDATAVEHICLELIC,:PICDATAVEHICLELICWATERMARK"; /* 上面的拼接語句比較復雜,下面是拼接之後的結果 string(1072) "INSERT INTO T_RRGU_SUBMITION (ID,LSH,VERFYTYPE,IDENTIFICATIONNO,REALNAME,PHONE,BINDDRIVELICENSE,PICDATAIDENTIFACE,PICDATAIDENTIFACEWATERMARK,PICDATAIDENTIBACK,PICDATAIDENTIBACKWATERMARK,PICDATAIDENTIPERSON,PICDATAIDENTIPERSONWATERMARK,DABH,CARINFOHPHM,CARINFOHPZL,CARINFOFDJH,PICDATAVEHICLELIC,PICDATAVEHICLELICWATERMARK,CREATED,SOURCETYPE,SOURCEAPP,JUDGESTATE,PUBLISHREULTTYPE,PUBLISHSTATE,QUERYPASSWORD,CONTACTADDRESS,ISLOCK) VALUES (sys_guid(),:lsh,:verfytype,:id,:realname,:phone,1,EMPTY_BLOB(),EMPTY_BLOB(),EMPTY_BLOB(),EMPTY_BLOB(),EMPTY_BLOB(),EMPTY_BLOB(),:dabh,:hphm,:hpzl,:fdjh,EMPTY_BLOB(),EMPTY_BLOB(),sysdate,:targetSourcetype,:sourcetype,0,-1,0,:mm,:contactAddress,0) RETURNING PICDATAIDENTIFACE,PICDATAIDENTIFACEWATERMARK,PICDATAIDENTIBACK,PICDATAIDENTIBACKWATERMARK,PICDATAIDENTIPERSON,PICDATAIDENTIPERSONWATERMARK,PICDATAVEHICLELIC,PICDATAVEHICLELICWATERMARK INTO :PICDATAIDENTIFACE,:PICDATAIDENTIFACEWATERMARK,:PICDATAIDENTIBACK,:PICDATAIDENTIBACKWATERMARK,:PICDATAIDENTIPERSON,:PICDATAIDENTIPERSONWATERMARK,:PICDATAVEHICLELIC,:PICDATAVEHICLELICWATERMARK" */ // 創建blob對象並且綁定數據 $stid = oci_parse($conn, $sql); $PICDATAIDENTIFACEblob = oci_new_descriptor($conn,OCI_D_LOB); $PICDATAIDENTIFACEWATERMARKblob = oci_new_descriptor($conn,OCI_D_LOB); $PICDATAIDENTIBACKblob = oci_new_descriptor($conn,OCI_D_LOB); $PICDATAIDENTIBACKWATERMARKblob = oci_new_descriptor($conn,OCI_D_LOB); $PICDATAIDENTIPERSONblob = oci_new_descriptor($conn,OCI_D_LOB); $PICDATAIDENTIPERSONWATERMARKblob = oci_new_descriptor($conn,OCI_D_LOB); oci_bind_by_name($stid, ‘:lsh‘, $lsh); oci_bind_by_name($stid, ‘:verfytype‘, $verfytype); oci_bind_by_name($stid, ‘:id‘, $id); oci_bind_by_name($stid, ‘:realname‘, $realname); oci_bind_by_name($stid, ‘:phone‘, $phone); oci_bind_by_name($stid, ‘:targetSourcetype‘, $targetSourcetype); oci_bind_by_name($stid, ‘:sourcetype‘, $sourcetype); oci_bind_by_name($stid, ‘:mm‘, $mm); oci_bind_by_name($stid, ‘:contactAddress‘, $contactAddress); //執行語句 oci_execute($stid, OCI_DEFAULT); //blob對象保存對應的圖片數據 if ($PICDATAIDENTIFACEblob->save(base64_decode($picIdentiFace)) && $PICDATAIDENTIFACEWATERMARKblob->save(base64_decode($picIdentiFaceWaterRemark)) && $PICDATAIDENTIBACKblob->save(base64_decode($picIdentiBack)) && $PICDATAIDENTIBACKWATERMARKblob->save(base64_decode($picIdentiBackWaterRemark)) && $PICDATAIDENTIPERSONblob->save(base64_decode($picIdentiWithUser)) && $PICDATAIDENTIPERSONWATERMARKblob->save(base64_decode($picIdentiWithUserWaterRemark))) { // On success, commit the transaction // var_dump("數據正確添加到數據庫中"); oci_commit($conn); oci_free_statement($stid); oci_close($conn); }else{ $error = oci_error(); echo $error; oci_rollback($conn); oci_free_statement($stid); oci_close($conn); $err = "內部錯誤!"; }

php 連接oracle插入多張圖片的方法