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

Posted Caersi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 连接oracle插入多张图片的方法相关的知识,希望对你有一定的参考价值。

  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插入多张图片的方法的主要内容,如果未能解决你的问题,请参考以下文章

多张图片上传通过 php 验证

php如何从数据库中读取多张图片的路径

php 提交表单,包含textarea和多张图片

怎么在DW中插入图片方法

怎样让多张图片双面打印按顺序打印?

移动端 canvas插入多张图片生成一张可保存到手机图片