OCI8PDO YII 1.1 Expansion and bandage of the Clob/blob parameters

Source: Internet
Author: User
Tags stmt yii
In I company there are project which is constructed on YII 1.1 and uses the Oracle 9g database. For work with base the OCI8PDO expansion is used.

Recently there is problem of loading of scans in base in the field of a BLOB. Since the author of expansion writes:
The goal of this PDO class are to simulate of 99% of the PDO functions. That's the reasons to doubt implementation of this functionality is little.

We try to load the scan:

<?php
    $doc _scan = file_get_contents ($file);
    $db = Yii::app ()->dboracle;
    $stmt = $db->createcommand ("Update scan_document set docum_scan=:d oc_xml, doc_scan=:d oc_scan where docum_id=:d ocum_ ID ");
    $stmt->bindparam (':d oc_xml ', $doc _xml, PDO::P aram_lob);
    $stmt->bindparam (':d oc_scan ', $doc _scan, PDO::P aram_lob);
    $stmt->bindvalue (':d ocum_id ', $add->docum_id);
    $stmt->query ();
? >

But far from it:ora-01465:invalid hex number.

began to light up problem and have come across implementation of the Bindparam method in the class oci8pdo_statement of th E above described expansion:

<?php Public Function Bindparam ($parameter, & $variable, $data _type = PDO::P aram_str, $length =-1, $driver _options = null) {//not checking for $data _type = = PDO::P aram_int, because this gives problems when insert
    ing/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, $para
    Meter, $variable, Count ($variable), $length);
        else {if ($length = = 1) {$length = strlen ((string) $variable);
    Return Oci_bind_by_name ($this->_sth, $parameter, $variable, $length); }}?>

The argument of $data _type is accepted, but are not processed anywhere. And it turns out this CLOB or BLOB to write at us would not leave. There was no. disappear, it is necessary to Dopilivat oci8pdo.

Have added constants and method to the class oci8pdo which are inherited from PDO the pulling-out resource of connection to 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;
    }
? >


And the Bindparam method in the class oci8pdo_statement there are some dopilila:

<?php Public Function Bindparam ($parameter, & $variable, $data _type = PDO::P aram_str, $length =-1, $driver _options = null) {//.... if ($data _type = = Oci8pdo::P
            Aram_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::P aram_clob) {$clob = Oci_new_descriptor ($this->_pdooci8->getdbh (), OC
            I_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); }}?>

Now processing of the CLOB/BLOB takes place successfully:

<?php

$doc _scan = file_get_contents ($file);
$db = Yii::app ()->dboracle;
$stmt = $db->createcommand ("Update scan_document set docum_scan=:d oc_xml, doc_scan=:d oc_scan where docum_id=:d ocum_ ID ");

$stmt->bindparam (':d oc_xml ', $doc _xml, Oci8pdo::P Aram_clob); Используемнашиконстанты
$stmt->bindparam (':d oc_scan ', $doc _scan, Oci8pdo::P aram_blob);//используемнаши Константы
$stmt->bindvalue (':d ocum_id ', $add->docum_id);
$stmt->query ();

? >

Result:

Has drunk up has been organized in pulrekvest and it are sent to the Oci8pdo Yjeroen. When the problem is Googled, many unresolved questions on this subject have been. I hope, my experience'll help somebody.

Https://github.com/yjeroen/oci8Pdo

http://developers-club.com/posts/267609/

https://habrahabr.ru/post/267609/

Working with lobs in Oracle and PHP

Http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.