最近、スキャンをBLOBフィールドのデータベースにロードするタスクがありました。 なぜなら 拡張機能の作者は次のように書いています:
このPDOクラスの目標は、アプリケーションで使用するPDO関数の99%をシミュレートすることです。この機能の実装を疑う理由はほとんどありませんでした。
スキャンをロードしてください:
<?php $doc_scan = file_get_contents($file); $db = Yii::app()->dbOracle; $stmt = $db->createCommand("update scan_document set DOCUM_SCAN=:doc_xml, DOC_SCAN=:doc_scan where DOCUM_ID=:docum_id"); $stmt->bindParam(':doc_xml', $doc_xml, PDO::PARAM_LOB); $stmt->bindParam(':doc_scan', $doc_scan, PDO::PARAM_LOB); $stmt->bindValue(':docum_id', $add->DOCUM_ID); $stmt->query(); ?>
ただし、 ORA-01465:16進数が無効です。
彼らは問題を明らかにし始め、上記の拡張機能のOci8PDO_StatementクラスのbindParamメソッドの実装につまずきました。
<?php public function bindParam( $parameter, &$variable, $data_type = PDO::PARAM_STR, $length = -1, $driver_options = null ) { //Not checking for $data_type === PDO::PARAM_INT, because this gives problems when inserting/updating integers into a VARCHAR column. if ($driver_options !== null) { throw new PDOException('$driver_options is not implemented for Oci8PDO_Statement::bindParam()'); } if (is_array($variable)) { return oci_bind_array_by_name( $this->_sth, $parameter, $variable, count($variable), $length ); } else { if ($length == -1) { $length = strlen((string)$variable); } return oci_bind_by_name($this->_sth, $parameter, $variable, $length); } } ?>
$ data_type引数は受け入れられますが、どこでも処理されません。 したがって、CLOBまたはBLOBを使用した書き込みは機能しません。 行くところがなかったので、oci8Pdoを終了しなければなりませんでした。
PDOから継承されたクラスOci8PDOに、定数と接続リソースをDBに引き出すメソッドが追加されました。
<?php /** * Ananalog constant OCI_B_CLOB * * @const int */ const PARAM_CLOB = 112; /** * Ananalog constant OCI_B_BLOB * * @const int */ const PARAM_BLOB = 113; // .............. /** * Return the resource connection * * @return mixed */ public function getDbh() { return $this->_dbh; } ?>
そして、Oci8PDO_StatementクラスのbindParamメソッドを少し使い終えました。
<?php public function bindParam( $parameter, &$variable, $data_type = PDO::PARAM_STR, $length = -1, $driver_options = null ) { // ................ if ($data_type == Oci8PDO::PARAM_BLOB) { $clob = oci_new_descriptor($this->_pdoOci8->getDbh(), OCI_D_LOB); $res = oci_bind_by_name($this->_sth, $parameter, $clob, -1, OCI_B_BLOB); $clob->writeTemporary($variable, OCI_TEMP_BLOB); return $res; } else if ($data_type == Oci8PDO::PARAM_CLOB) { $clob = oci_new_descriptor($this->_pdoOci8->getDbh(), OCI_D_LOB); $res = oci_bind_by_name($this->_sth, $parameter, $clob, -1, OCI_B_CLOB); $clob->writeTemporary($variable, OCI_TEMP_CLOB); return $res; } else { return oci_bind_by_name($this->_sth, $parameter, $variable, $length); } } ?>
これで、CLOB / BLOB処理が成功しました。
<?php $doc_scan = file_get_contents($file); $db = Yii::app()->dbOracle; $stmt = $db->createCommand("update scan_document set DOCUM_SCAN=:doc_xml, DOC_SCAN=:doc_scan where DOCUM_ID=:docum_id"); $stmt->bindParam(':doc_xml', $doc_xml, Oci8PDO::PARAM_CLOB); // $stmt->bindParam(':doc_scan', $doc_scan, Oci8PDO::PARAM_BLOB); // $stmt->bindValue(':docum_id', $add->DOCUM_ID); $stmt->query(); ?>
結果:
dopilはpullrequestにまとめられ、開発者oci8Pdo yjeroenに送信されました。 問題がグーグルで調べられたとき、このトピックに関する多くの未解決の質問に気づきました。 私の経験が誰かを助けることを願っています。
PS:コメントの中で批判と建設的なコメントをうれしく思います。