码迷,mamicode.com
首页 > 数据库 > 详细

php 连接oracle插入多张图片的方法

时间:2017-08-30 00:57:10      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:直接   ide   publish   value   license   绑定   base64   new   user   

  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插入多张图片的方法

标签:直接   ide   publish   value   license   绑定   base64   new   user   

原文地址:http://www.cnblogs.com/Caersi/p/7451007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!