Oci_free_statement() ..??

oci_free_statement() frees resources associated with Oracle's cursor or statement, which was received from as a result of oci_parse() or obtained from Oracle.
What happens if you do not use the oci_free_statement after the oci_execute?
Will PHP use more memory? or ? or ?

Although it makes good practice to free resources after use, generally it doesn't matter if you don't on the average web page as PHP will free the resources automatically at the end of the script execution. If you're using PHP to do a lot of data processing then it's recommended to use it where necessary to keep the script overheads to a minimum.

Similar Messages

  • Oracle and php 5.4 doesn't work

    Description:
    I was using php 5.3 with oracle client 11g and everything works fine. I have a wep app already in production with php5.3. I tried upgrade to php5.4, so I install in another folder XAMPP 1.8 who uses php 5.4. I tried everything to make oracle works, but I cannot connect in the database. Its really strange because in the same machine with the same remote database php 5.3 works just fine.
    I am using in php 5.3 o php_oci8.dll with oracle client 11g
    and with php5.4 I tried use php_oci8.dll. The error is:
    ORA-12154: TNS:could not resolve the connect identifier specified
    after I tried php_oci8_11g.dll and the the error is:
    ORA-24315: illegal attribute type
    I on a Windows Vista 64bit Machine,
    Both php are 32bis,
    oracle client is 32bits
    The database is in another machine.
    I think that everything that you need to simulate the problem is install XAMPP 1.8, enable php_oci8.dll and try run the test script.
    Test script:
    print_r(get_loaded_extensions());
    print_r(get_extension_funcs('oci8'));
    echo system('env');
    echo "Client Version: " . oci_client_version();
    print_r(oci_pconnect(DBUSER, DBPASSWORD, DBTNS));
    print_r(oci_error());
    die();
    Expected result:
    I was expecting that the oci_pconnect works, because the same script with php 5.3, works.
    Actual result:
    Array
    [0] => Core
    [1] => bcmath
    [2] => calendar
    [3] => com_dotnet
    [4] => ctype
    [5] => date
    [6] => ereg
    [7] => filter
    [8] => ftp
    [9] => hash
    [10] => iconv
    [11] => json
    [12] => mcrypt
    [13] => SPL
    [14] => odbc
    [15] => pcre
    [16] => Reflection
    [17] => session
    [18] => standard
    [19] => mysqlnd
    [20] => tokenizer
    [21] => zip
    [22] => zlib
    [23] => libxml
    [24] => dom
    [25] => PDO
    [26] => bz2
    [27] => SimpleXML
    [28] => wddx
    [29] => xml
    [30] => xmlreader
    [31] => xmlwriter
    [32] => apache2handler
    [33] => Phar
    [34] => mbstring
    [35] => exif
    [36] => gd
    [37] => gettext
    [38] => mysql
    [39] => mysqli
    [40] => oci8
    [41] => pdo_mysql
    [42] => pdo_sqlite
    [43] => soap
    [44] => sockets
    [45] => sqlite3
    [46] => xmlrpc
    [47] => xsl
    [48] => mhash
    Array
    [0] => oci_define_by_name
    [1] => oci_bind_by_name
    [2] => oci_bind_array_by_name
    [3] => oci_field_is_null
    [4] => oci_field_name
    [5] => oci_field_size
    [6] => oci_field_scale
    [7] => oci_field_precision
    [8] => oci_field_type
    [9] => oci_field_type_raw
    [10] => oci_execute
    [11] => oci_cancel
    [12] => oci_fetch
    [13] => oci_fetch_object
    [14] => oci_fetch_row
    [15] => oci_fetch_assoc
    [16] => oci_fetch_array
    [17] => ocifetchinto
    [18] => oci_fetch_all
    [19] => oci_free_statement
    [20] => oci_internal_debug
    [21] => oci_num_fields
    [22] => oci_parse
    [23] => oci_new_cursor
    [24] => oci_result
    [25] => oci_client_version
    [26] => oci_server_version
    [27] => oci_statement_type
    [28] => oci_num_rows
    [29] => oci_close
    [30] => oci_connect
    [31] => oci_new_connect
    [32] => oci_pconnect
    [33] => oci_error
    [34] => oci_free_descriptor
    [35] => oci_lob_save
    [36] => oci_lob_import
    [37] => oci_lob_size
    [38] => oci_lob_load
    [39] => oci_lob_read
    [40] => oci_lob_eof
    [41] => oci_lob_tell
    [42] => oci_lob_truncate
    [43] => oci_lob_erase
    [44] => oci_lob_flush
    [45] => ocisetbufferinglob
    [46] => ocigetbufferinglob
    [47] => oci_lob_is_equal
    [48] => oci_lob_rewind
    [49] => oci_lob_write
    [50] => oci_lob_append
    [51] => oci_lob_copy
    [52] => oci_lob_export
    [53] => oci_lob_seek
    [54] => oci_commit
    [55] => oci_rollback
    [56] => oci_new_descriptor
    [57] => oci_set_prefetch
    [58] => oci_set_client_identifier
    [59] => oci_set_edition
    [60] => oci_set_module_name
    [61] => oci_set_action
    [62] => oci_set_client_info
    [63] => oci_password_change
    [64] => oci_free_collection
    [65] => oci_collection_append
    [66] => oci_collection_element_get
    [67] => oci_collection_element_assign
    [68] => oci_collection_assign
    [69] => oci_collection_size
    [70] => oci_collection_max
    [71] => oci_collection_trim
    [72] => oci_new_collection
    [73] => oci_free_cursor
    [74] => ocifreecursor
    [75] => ocibindbyname
    [76] => ocidefinebyname
    [77] => ocicolumnisnull
    [78] => ocicolumnname
    [79] => ocicolumnsize
    [80] => ocicolumnscale
    [81] => ocicolumnprecision
    [82] => ocicolumntype
    [83] => ocicolumntyperaw
    [84] => ociexecute
    [85] => ocicancel
    [86] => ocifetch
    [87] => ocifetchstatement
    [88] => ocifreestatement
    [89] => ociinternaldebug
    [90] => ocinumcols
    [91] => ociparse
    [92] => ocinewcursor
    [93] => ociresult
    [94] => ociserverversion
    [95] => ocistatementtype
    [96] => ocirowcount
    [97] => ocilogoff
    [98] => ocilogon
    [99] => ocinlogon
    [100] => ociplogon
    [101] => ocierror
    [102] => ocifreedesc
    [103] => ocisavelob
    [104] => ocisavelobfile
    [105] => ociwritelobtofile
    [106] => ociloadlob
    [107] => ocicommit
    [108] => ocirollback
    [109] => ocinewdescriptor
    [110] => ocisetprefetch
    [111] => ocipasswordchange
    [112] => ocifreecollection
    [113] => ocinewcollection
    [114] => ocicollappend
    [115] => ocicollgetelem
    [116] => ocicollassignelem
    [117] => ocicollsize
    [118] => ocicollmax
    [119] => ocicolltrim
    Client Version: 11.1.0.6.0
    <b>Warning</b>: oci_pconnect(): in <b>C:\xampp18\htdocs\config\aguaCheiro.php</b> on line <b>25</b>
    Array
    => 24315
        [message] => ORA-24315: invalid atribute type
        [offset] => 0
        [sqltext] =>

    It strongly sounds like you have multiple versions of Oracle libraries and are seeing some kind of clash.

  • Inserting image in a table using php +zend

    Hy!
    The table is
    (products(picture_p blob,prod_id number)) when i try to insert the pictureusing a similar code with this from oracle .com:
    // Insert the BLOB from PHP's tempory upload area
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) '
    .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
    oci_execute($stmt, OCI_DEFAULT);
    // The function $lob->savefile(...) reads from the uploaded file.
    // If the data was already in a PHP variable $myv, the
    // $lob->save($myv) function could be used instead.
    if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($conn);
    else {
    echo "Couldn't upload Blob\n";
    $lob->free();
    oci_free_statement($stmt);
    // Now query the uploaded BLOB and display it
    $query = 'SELECT BLOBDATA FROM BTAB WHERE BLOBID = :MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_execute($stmt, OCI_DEFAULT);
    $arr = oci_fetch_assoc($stmt);
    $result = $arr['BLOBDATA']->load();
    // If any text (or whitespace!) is printed before this header is sent,
    // the text won't be displayed and the image won't display properly.
    // Comment out this line to see the text and debug such a problem.
    header("Content-type: image/JPEG");
    echo $result;
    oci_free_statement($stmt);
    oci_close($conn); // log off
    ?>
    I get an error -can't open file htdocs/ phpA.tmp
    please if you have an idea from where it could be the error reply

    It looks like your webserver doesn't have read permissions on the directory and files within it. In Linux, set it to 755, in Windows, I'm not sure what needs doing sorry.

  • How can i insert  more clob objects into oracle9i?

    my env:
    os: windows server 2003 ent sp2
    php:=5.2.3
    oracle : 9.0.0.8
    i look at this article :
    http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_lobs.html
    but ,i want insert two clob into the oracle ....
    Inserting a LOB
    To INSERT an internal LOB, you first need to initialize the LOB using the respective Oracle EMPTY_BLOB or EMPTY_CLOB functions—you cannot update a LOB that contains a NULL value.
    Once initialized, you then bind the column to a PHP OCI-Lob object and update the LOB content via the object's save() method.
    The following script provides an example, returning the LOB type from the INSERT query:
    <?php
    // connect to DB etc...
    $sql = "INSERT INTO
    mylobs
    id,
    mylob
    VALUES
    mylobs_id_seq.NEXTVAL,
    --Initialize as an empty CLOB
    EMPTY_CLOB()
    RETURNING
    --Return the LOB locator
    mylob INTO :mylob_loc";
    $stmt = oci_parse($conn, $sql);
    // Creates an "empty" OCI-Lob object to bind to the locator
    $myLOB = oci_new_descriptor($conn, OCI_D_LOB);
    // Bind the returned Oracle LOB locator to the PHP LOB object
    oci_bind_by_name($stmt, ":mylob_loc", $myLOB, -1, OCI_B_CLOB);
    // Execute the statement using , OCI_DEFAULT - as a transaction
    oci_execute($stmt, OCI_DEFAULT)
    or die ("Unable to execute query\n");
    // Now save a value to the LOB
    if ( !$myLOB->save('INSERT: '.date('H:i:s',time())) ) {
    // On error, rollback the transaction
    oci_rollback($conn);
    } else {
    // On success, commit the transaction
    oci_commit($conn);
    // Free resources
    oci_free_statement($stmt);
    $myLOB->free();
    // disconnect from DB etc.
    ?>

    Use something like:
    sql = "INSERT INTO mylobs (id, mylob1, mylob2) VALUES
    (mylobs_id_seq.NEXTVAL, EMPTY_CLOB(), EMPTY_CLOB()) RETURNING
    mylob1, mylob2 INTO :mylob_loc1, :mylob_loc2";
    You'll need to allocated two lob descriptors and bind both to the statement.
    -- cj

  • How to load folder with images php with oracle

    Hi i want to upload from my php form folder with images what should i fix in my php code for 1 image?
    <?php
    define("ORA_CON_UN", "obrazy");
    define("ORA_CON_PW", "miksas1");
    define("ORA_CON_DB", "//localhost/orcl");
    if (!isset($_FILES['lob_upload'])) {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
    enctype="multipart/form-data">
    Image filename: <input type="file" name="lob_upload">
    <input type="submit" value="Upload">
    </form>
    <?php
    else {
    $conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
    // Insert the BLOB from PHP's tempory upload area
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn, 'INSERT INTO FOTKI (FOTKAID, FOTKA) '
    .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING FOTKA INTO :FOTKA');
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_bind_by_name($stmt, ':FOTKA', $lob, -1, OCI_B_BLOB);
    oci_execute($stmt, OCI_DEFAULT);
    // The function $lob->savefile(...) reads from the uploaded file.
    // If the data was already in a PHP variable $myv, the
    // $lob->save($myv) function could be used instead.
    if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($conn);
    echo '<p>Obrazek załadowano</p>';
    else {
    echo "Couldn't upload Blob\n";
    $lob->free();
    oci_free_statement($stmt);
    oci_close($conn); // log off
    ?>

    The first thing I'd suggest you fix is the forum to which you posted the question.
    The name of this forum is "Oracle Database General Questions." That is questions about the database ... not questions about PHP.
    Look further and you will find the correct forum.

  • Php page won't display the first record

    I have the following code, but it always skip the first row of the records pull from an Oracle table:
    include "utility_functions.php";
    // Form the query and execute it
    $sql = "select * from dept where cid=".$_GET['q'];
    $result_array = execute_sql_in_oracle ($sql);
    $result = $result_array["flag"];
    $cursor = $result_array["cursor"];
    if ($result == false){
      display_oracle_error_message($cursor);
      die("Client Query Failed.");
    // Display the query results
    echo "<ul class=\"nav\">";
    $values = oci_fetch_array ($cursor);
    //echo $values[0];
    // Fetch the result from the cursor one by one
    while ($values = oci_fetch_array($cursor)){
      $did = $values[0];
      $dname = $values[1];
      echo("<li><a href=\"showdetail.php?did=$did\">$dname</a></li> ");
    oci_free_statement($cursor);
    echo "</ul>";
    for example, I have the following in dept table:
    did    dname
    1     Business
    2     Education
    3     Math
    4     English
    It will only list: education, math, and english.  Any clues?

    What does execute_sql_in_oracle() do?
    Try following example code, such as from:
            http://www.php.net/manual/en/oci8.examples.php
            http://www.php.net/manual/en/function.oci-fetch-array.php
            http://www.php.net/manual/en/function.oci-bind-by-name.php
    It's extremely insecure (and slow) to do a query made up with string concatenation like:
      $sql = "select * from dept where cid=".$_GET['q'];
    You probably need to first sanitize $_GET to remove anything malicious.  Then you must use a bind variable on the sanitized result.

  • PHP 5 Code to Upload and Retrieve an Image (aka BLOB) with Oracle

    I keep being asked about BLOBs. For posterity, here is my example updated
    to use the new PHP 5 OCI8 function names, and using bind variables for the BLOB id.
    -- cj
    <?php
    // Sample form to upload and insert an image into an ORACLE BLOB
    // column using PHP 5's OCI8 API. 
    // Note: Uses the new PHP 5 names for OCI8 functions.
    // Before running this script, execute these statements in SQL*Plus:
    //   drop table btab;
    //   create table btab (blobid number, blobdata blob);
    // This example uploads an image file and inserts it into a BLOB
    // column.  The image is retrieved back from the column and displayed.
    // Make sure there is no whitespace before "<?php" else the wrong HTTP
    // header will be sent and the image won't display properly.
    // Make sure php.ini's value for upload_max_filesize is large enough
    // for the largest lob to be uploaded.
    // Tested with Zend Core for Oracle 1.3 (i.e. PHP 5.0.5) with Oracle 10.2
    // Based on a sample originally found in
    //     http://www.php.net/manual/en/function.ocinewdescriptor.php
    $myblobid = 1;  // should really be a unique id e.g. a sequence number
    define("ORA_CON_UN", "hr");             // username
    define("ORA_CON_PW", "hr");             // password
    define("ORA_CON_DB", "//localhost/XE"); // connection string
    if (!isset($_FILES['lob_upload'])) {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
       enctype="multipart/form-data">
    Image filename: <input type="file" name="lob_upload">
    <input type="submit" value="Upload">
    </form>
    <?php
    else {
      $conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
      // Delete any existing BLOB so the query at the bottom
      // displays the new data
      $query = 'DELETE FROM BTAB WHERE BLOBID = :MYBLOBID';
      $stmt = oci_parse ($conn, $query);
      oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
      $e = oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
      if (!$e) {
        die;
      oci_free_statement($stmt);
      // Insert the BLOB from PHP's tempory upload area
      $lob = oci_new_descriptor($conn, OCI_D_LOB);
      $stmt = oci_parse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) '
             .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
      oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
      oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
      oci_execute($stmt, OCI_DEFAULT);
      // The function $lob->savefile(...) reads from the uploaded file.
      // If the data was already in a PHP variable $myv, the
      // $lob->save($myv) function could be used instead.
      if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
        oci_commit($conn);
      else {
        echo "Couldn't upload Blob\n";
      $lob->free();
      oci_free_statement($stmt);
      // Now query the uploaded BLOB and display it
      $query = 'SELECT BLOBDATA FROM BTAB WHERE BLOBID = :MYBLOBID';
      $stmt = oci_parse ($conn, $query);
      oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
      oci_execute($stmt, OCI_DEFAULT);
      $arr = oci_fetch_assoc($stmt);
      $result = $arr['BLOBDATA']->load();
      // If any text (or whitespace!) is printed before this header is sent,
      // the text won't be displayed and the image won't display properly.
      // Comment out this line to see the text and debug such a problem.
      header("Content-type: image/JPEG");
      echo $result;
      oci_free_statement($stmt);
      oci_close($conn); // log off
    ?>

    I am using oracle 10g [10.2.0.1.0] and PHP 4.3.9 with Apache.
    I tried my best to change the old functions names for example(oci_fetch)
    to the new (OCIFetch),i works every where, but i could not find the corresponded functions of (oci_fetch_assoc) that's why i can not see my BLOBS at all!
    Can some help me please, to know where are corresponded functions of oracle 8 to oracle 10g?
    Exactly here is my problem:
    $query = 'SELECT BLOBDATA FROM BTAB WHERE BLOBID = :MYBLOBID';
    $stmt = ociparse ($conn, $query);
    OCIBindByName($stmt, ':MYBLOBID', $myblobid);
    ociexecute($stmt, OCIDEFAULT);
    $arr = oci_fetch_assoc($stmt);
    // OCIFetchAssoc, OCIFetch, OCI_ASSOC ... nothing works-> Fatal error: Call to undefined function:
    $result = $arr['BLOBDATA']->load();
    What should i do?
    Thanky very much.

  • Need help running a function in a package

    Hi,
    I am trying to execute a function called "IsGuest" which is stored in a package called "PK_USER_ROLE". This procedure returns a boolean as a result. Here is the PHP code in the web page I am using:
         echo "<br/>Test to execute a stored procedure";
         $s = oci_parse($conn, "begin :ret := PK_USER_ROLE.IsGuest(:userid); end;") or die ('Can not parse query');
         $myid = "huppe";
         oci_bind_by_name($s, ':ret', $r, 40);
         oci_bind_by_name($s, ':userid', $myid);
         oci_execute($s);
         echo "<br/>result=".$r;
         echo "<br/>Completed<br/><br/>";
         oci_free_statement($s);
         oci_close($conn);
    In Oracle, here is the package definition:
    create or replace
    PACKAGE PK_USER_ROLE IS
    function IsGuest (i_unique_id in varchar2) return boolean;
    END;
    All I get back when I view the PHP file in the browser is:
    Test to execute a stored procedure
    result=
    Completed
    PHP 5.3.8
    Oracle 11g
    OCI8 extension
    Any help would be appreciated

    I find it helpful to turn on errors and warnings in php.ini during
    development.
        display_errors  = On
        error_reporting = E_ALL | E_STRICTor use the ini_set() equivalents in your script. For production,
    make sure errors are logged but not displayed to users.
    Your script then gives:
        $ php54 t.php
        Test to execute a stored procedurePHP Warning:  oci_execute(): ORA-06550: line 1, column 15:
        PLS-00382: expression is of wrong type
        ORA-06550: line 1, column 7:
        PL/SQL: Statement ignored in /tmp/t.php on line 10
        Warning: oci_execute(): ORA-06550: line 1, column 15:
        PLS-00382: expression is of wrong type
        ORA-06550: line 1, column 7:
        PL/SQL: Statement ignored in /tmp/t.php on line 10See the comment below the table in
    http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci03typ.htm#CEGIEEJI
    +"The following two types are internal to PL/SQL and cannot be returned as values by OCI:+
    +Boolean, SQLT_BOL+
    +Record, SQLT_REC"+
    Since PHP OCI8 is written in OCI, this limitation is inherited.
    Try something like:
      $s = oci_parse($conn, "begin if (IsGuest(:userid) = true) then :ret := 1; else :ret := 0; end if; end;") or die ('Can not parse query');

  • Displaying a BLOB image

    Hi, i got a trouble to display the image in BLOB
    i have win2k3, oracle 10.2 g, php 5
    when i upload the image, the browser send this:
    Error CGI
    La aplicación CGI especificada puede comportarse de forma anormal si no recibe un conjunto completo de encabezados HTTP.
    i'l agree your help,
    the code is:
    <?php
    // Sample form to upload and insert an image into an ORACLE BLOB
    // column using PHP5's OCI8 API.
    // Before running this script, execute these statements in SQL*Plus:
    // drop table btab;
    // create table btab (blobid number, blobdata blob);
    // This example uploads an JPG file and inserts it into a BLOB
    // column. The image is retrieved back from the column and displayed.
    // Make sure there is no whitespace before "<?php" else the wrong HTTP
    // header will be sent and the image won't display properly.
    // Based on a sample originally found in
    // http://www.php.net/manual/en/function.ocinewdescriptor.php
    $myblobid = 1; // should really be a unique id e.g. a sequence number
    define("ORA_CON_UN", "username"); // username
    define("ORA_CON_PW", "passwd"); // password
    define("ORA_CON_DB", "connstring"); // connection string
    if (!isset($_FILES['lob_upload'])) {
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
    enctype="multipart/form-data">
    Image filename: <input type="file" name="lob_upload">
    <input type="submit" value="Upload">
    </form>
    <?php
    else {
    $conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
    // Delete any existing BLOB so the query at the bottom
    // displays the new data
    $query = 'DELETE FROM BTAB WHERE BLOBID = :MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    $e = oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
    if (!$e) {
    die;
    oci_free_statement($stmt);
    // Insert the BLOB from PHP's tempory upload area
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn, 'INSERT INTO BTAB (BLOBID, BLOBDATA) '
    .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING BLOBDATA INTO :BLOBDATA');
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
    oci_execute($stmt, OCI_DEFAULT);
    // The function $lob->savefile(...) reads from the uploaded file.
    // If the data was already in a PHP variable $myv, the
    // $lob->save($myv) function could be used instead.
    if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($conn);
    else {
    echo "Couldn't upload Blob\n";
    $lob->free();
    oci_free_statement($stmt);
    // Now query the uploaded BLOB and display it
    $query = 'SELECT BLOBDATA FROM BTAB WHERE BLOBID = :MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_execute($stmt, OCI_DEFAULT);
    $arr = oci_fetch_assoc($stmt);
    $result = $arr['BLOBDATA']->load();
    // If any text (or whitespace!) is printed before this header is sent,
    // the text won't be displayed and the image won't display properly.
    // Comment out this line to see the text and debug such a problem.
    header("Content-type: image/jpeg");
    echo $result;
    oci_free_statement($stmt);
    oci_close($conn); // log off
    ?>

    Hi, i got a trouble to display the image in BLOB
    i have win2k3, oracle 10.2 g, php 5Which version of PHP 5? Some LOB handling got broken and fixed along the way.
    Try the latest DLL from http://pecl4win.php.net/ext.php/php_oci8.dll
    -- cj

  • Zend v2 + oracle 10 + blob problem

    Hi all,
    I have a problem with display an images. Script looks like that:
    <?
    $myblobid = 1;
    $conn = oci_connect('tmp', 'tmp','db');
    $query = 'select * from photos_blob where id=:MYBLOBID';
    $stmt = oci_parse ($conn, $query);
    oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
    oci_execute($stmt);
    $arr = oci_fetch_assoc($stmt);
    $result = $arr['photo']->load();
    header("Content-type: image/jpeg");
    echo $result;
    oci_free_statement($stmt);
    oci_close($conn);
    ?>
    and I can not see a picture. I believe that this script works good because when I delete a "header("Content-type: image/jpeg");" i see a binary data.
    Any ideas?
    Best regards.

    You have posted your question to an inappropriate group.
    Please review the list of topics and choose more wisely. <g>

  • Escaping of special signs, once it works, once not

    Hi all,
    I would like to ask a simple question, I believe some of you know this issue already and know how to solve it, I googled an hour, changed the code 100 times, but with the first $query I get always "Execute not successful."
    Does anyone know how to solve this?
           $query = "
                select
                    t.snap_time,
                    n.value-lag(n.value,1,n.value) over (order by n.name,n.snap_id) lag
                from stats\$sysstat n,stats\$snapshot t 
                where
                n.snap_id in (select snap_id from stats\$snapshot where snap_time between :low and :high )
                and n.name = :statname
                and t.snap_id=n.snap_id
                order by 1,2 " ;
            //$query = "select * from stats\$snapshot where rownum<=:bind" ;
    function doQuery($conn,$query) {
                try {
                $stmt = oci_parse($conn, $query) ;
                $low = '25-03-2015 10:00:00';
                $high = '25-03-2015 21:00:00';
                $statname = 'parse count (total)';
                oci_bind_by_name($stmt, ":low", $low ) ;
                oci_bind_by_name($stmt, ":high", $high ) ;
                oci_bind_by_name($stmt, ":statname", $statname ) ;
                //$val = 1;
                //oci_bind_by_name($stmt, ":bind", $val) ;
                // Perform the logic of the query
                $status = oci_execute($stmt);
                if ($status){
                while (($row = oci_fetch_assoc($stmt)) != false){
                    // Do something
                    var_dump($row) ;
                } else {
                    echo 'Execute not successful.<br>';
                oci_free_statement($query) ;
                } catch (Exception $e){
                    echo $e->getMessage() ;

    Hi, I tried it now, but it does not work, too. The purpose is to generate graphs later, get the data would be nice, creating synonyms on 500 databases without a change request is not really a good solution.
    If I echo the query I get:
    select t.snap_time, n.value-lag(n.value,1,n.value) over (order by n.name,n.snap_id) lag from stats$sysstat n,stats$snapshot t where n.snap_id in (select snap_id from stats$snapshot where snap_time between :low and :high ) and n.name = :statname and t.snap_id=n.snap_id order by 1,2
    Execute not successful.
    0.06801 ms
    Edit: after adding some debug info:
                $status = oci_execute($stmt) ;
                if (!$status) {
                    $e = oci_error($stmt) ;
                    var_dump($e);
    I get:
    array (size=4)
      'code' => int 1830
      'message' => string 'ORA-01830: zadan� form�t d�tumu neposta?uje pre �pln� konvertovanie vstupn�ho re?azca' (length=85)
      'offset' => int 279
      'sqltext' => string 'select
      t.snap_time,
      n.value-lag(n.value,1,n.value) over (order by n.name,n.snap_id) lag
      from stats$sysstat n,stats$snapshot t 
      where
      n.snap_id in (select snap_id from stats$snapshot where snap_time between :low and :high )
      and n.name = :statname
      and t.snap_id=n.snap_id
      order by 1,2 ' (length=393)
    So it means my date format is not good.

  • Saving a file to a BLOB and back...

    Hello everyone.
    I'm trying to save a file to a blob, and recover the blob value later to save to a file, but i'm having problems.
    I'm recording and retrieving the data sucessfuly, but the file written is like corrupted. But it is with the same filesize as the original one.
    This is how i'm doing:
    Recording the file to the database (BLOB):
    <?
    $conn = oci_connect('USER_NAME', 'PASSWORD', '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MYSERVER)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MYSERVICENAME)))');
    $filePath = '/var/www/html/Something.png';
    $fileOut = '/var/www/html/fileback.png';
    $codigo = 5;
    $blob = oci_new_descriptor($conn, OCI_D_LOB);
    $sql =
    "begin
       insert into MYTABLE (COD, FILE) values (:COD, :FILE);
    exception
      when dup_val_on_index then
         update MYTABLE set FILE = :FILE where COD = :COD;
    end;";
    // Parse the query
    $stid = oci_parse($conn, $sql);
    // Bind values
    oci_bind_by_name($stid, ":COD",  $codigo);
    oci_bind_by_name($stid, ":FILE", $blob, -1, OCI_B_BLOB);
    // Get the file
    $file = fopen($filePath, 'rb');
    // Read file content
    $fileContent = fread($file, filesize($filePath));
    // Write file content to the BLOB
    $blob->writeTemporary($fileContent);
    // Execute the statement
    $r = oci_execute($stid, OCI_DEFAULT);
    // Commit
    oci_commit($conn);
    // Close BLOB descriptor
    $blob->close();
    // Release the statement and close the connection
    oci_free_statement($stid);
    oci_close($conn);
    Retrieving the BLOB value:
    $conn = oci_connect('USER_NAME', 'PASSWORD', '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MYSERVER)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=MYSERVICENAME)))');
    $filePath = '/var/www/html/Something.png';
    $fileOut = '/var/www/html/fileback.png';
    $codigo = 5;
    $sql = 'select * from MYTABLE where COD = :COD';
    $stmt = oci_parse($conn, $sql);
    oci_bind_by_name($stmt, ":COD", $codigo);
    $result = oci_execute($stmt);
    $a = oci_fetch_array($stmt, OCI_RETURN_NULLS);
    $a['FILE']->export($fileOut);   // Don't work
    //file_put_contents($fileOut, $a['FILE']->read($a['FILE']->size()), FILE_BINARY);   // Don't work
    //file_put_contents($fileOut, $a['FILE']->load(), FILE_BINARY);   // Don't work
    fwrite(fopen($fileOut, 'rwb'), $a['FILE']->load());
    oci_close($conn);If someone can help me with anything i appreciate, thanks.
    Edited by: user1977051 on 12/06/2009 10:33

    I solved it.
    The problem is because the execute after the blob write:
    // Write file content to the BLOB
    $blob->writeTemporary($fileContent);
    // Execute the statement
    $r = oci_execute($stid, OCI_DEFAULT);and should be:
    // Execute the statement
    $r = oci_execute($stid, OCI_DEFAULT);
    // Write file content to the BLOB
    $blob->writeTemporary($fileContent);
    // i'm using this instead
    $blob->saveFile($filePath);Thanks.

  • Connecting PHP 5.0.3 to Oracle 10g

    I have read dozens of documents and postings, but I cannot identify why my PHP scripts fail to connect to my db.
    When I run:
    $connection = OCI_Connect('db_user_name', 'pw', 'db');
    I consistently get:
    Warning: oci_connect() [function.oci-connect]: ociopen_server:
    I have: Oracle 10g, PHP 5.0.3, MS IIS 5.0
    1. phpinfo() executes without any errors.
    2. phpinfo() reports: the correct location of my php.ini, the correct location of my extensions, and the correct values of my enviroment variables (ORACLE_HOME and ORACLE_SID.)
    3. I have un-commented php_oci8.dll in php.ini (phpinfo reports it as enabled.)
    4. I have installed the Oracle 10g client on the web server and can connect to the db from the web server using SQLPlus.
    5. I have given IUSR_<machine name> on my web server "Full Control" priviledges in both the Oracle client directory and the PHP directory.
    I must still be missing something though.... Does anyone know what?
    Thanks for your help - Chris

    I had similar problem…
    From dos
    set path=%PATH%;”path to php”;’path to php\ext”
    D:\ My Documents>more tst.php
    <?php
    $user="SCOTT";
    $password="tiger";
    $dbname="test";
    $connection = ocilogon($user, $password, $dbname);
    $query = "SELECT EMPNO,ENAME,JOB FROM emp";
    $statement = oci_parse ($connection, $query);
    oci_execute ($statement);
    while ($row = oci_fetch_array ($statement, OCI_ASSOC)) {
    $id = $row['EMPNO'];
    $name = $row['ENAME'];
    $lob_field = $row['JOB'];
    echo $id.' '.$name.' '.$lob_field,"\n";
    oci_free_statement($statement);
    oci_close($connection);
    ?>
    D: \My Documents>php tst.php
    7369 SMITH CLERK
    7499 ALLEN SALESMAN
    7521 WARD SALESMAN
    7566 JONES MANAGER
    D:\My Documents>
    Now it should work
    Robert

  • Updating two table from a single query

    I have two table such as
    user_log(user_id , password)
    and
    user_info(user_id , name , age , address , sex , email , contact)
    If I want to add data from a single form in php then what is the query?

    Hi,
    welcome to the forum..! plesae always post table data and expected result to help forum members help you better.
    From what I understand, all you need is a join on userid (assuming userid is unique/primary key )
    select ul.userid,
             ul.password,
            ui.name,
            ui.age
      from user_log ul,
              user_info ui
      where ul.user_id = ui.user_id
        ---- and any otehr condition for the user that you need.(where clause)In PHP......(based on this link.. http://wiki.oracle.com/page/PHP+Oracle+FAQ
    haven't tested the code.. )
    <?php
    $conn = oci_connect("scott", "tiger", "localhost/XE");
    if (!$conn) {
    $m = oci_error();
    echo $m["message"];
    exit;
    $stid = oci_parse($conn, "select ul.userid,
             ul.password,
            ui.name,
            ui.age
      from user_log ul,
              user_info ui
      where ul.user_id = ui.user_id");
    oci_execute($stid);
    // Query the table
    echo "<table border='1'>";
    while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>";
    foreach ($row as $item) {
    echo "<td>".($item!==null?htmlentities($item):" ")."</td>";
    echo "</tr>".PHP_EOL;
    echo "</table>";
    oci_free_statement($stid);
    oci_close($conn);
    ?>Try to provide more details.. if this is not what you are looking for.
    Hope this helps,
    Rajesh.

  • Oci_close does not release the connection when using DRCP

    Hello everyone,
    we are currently testing the deplyment of DRCP with 11g. I have the whole thing setup (correctly to my best knowledge), but I am facing an issue. The call to oci_close does not seem to release the connection to the pool as I would expect and therefore we see similar behavior like we were getting without using the DRCP.
    Our setup is using two RAC instances running 11.1.0.6.0, I am using PHP 5.1.6 with PECL installed oci8 1.3.4. The DRCP pool is configured and started, each with 100 max servers.
    When the webserver is idle it looks, well, idle.
    SQL> SELECT INST_ID,NUM_BUSY_SERVERS FROM GV$CPOOL_STATS;
    INST_ID NUM_BUSY_SERVERS
    1 0
    2 0
    The script is as simple as it gets:
    <?php
    $c = oci_pconnect('scott','tiger','IWPPOOLED');
    $s = oci_parse($c, 'select * from emp');
    $r = oci_execute($s, OCI_DEFAULT);
    oci_close($c);
    sleep(30);
    ?>
    What I would expect is that the script would connect to the pool, do the work for a tiny moment and then release the connection for usage by other script.
    But after I point the browser to the script, I get a 30 second loading time (as expected) but the server is busy all the time, like this:
    SQL> SELECT INST_ID,NUM_BUSY_SERVERS FROM GV$CPOOL_STATS;
    INST_ID NUM_BUSY_SERVERS
    1 0
    2 1
    After the 30 second sleep, it is released and busy servers are back to 0.
    If I load the server with ab using 256 connections:
    ab -n 1000000 -c 256 -k http://mywebserver/ocitest.php
    the pool is maxed out and the connects are stalling:
    SQL> SELECT INST_ID,NUM_BUSY_SERVERS FROM GV$CPOOL_STATS;
    INST_ID NUM_BUSY_SERVERS
    1 95
    2 95
    My network config for this service is following:
    IWPPOOLED =
    (DESCRIPTION =
    (LOAD_BALANCE=ON)
    (FAILOVER=ON)
    (ADDRESS = (PROTOCOL = tcp)(HOST = 10.1.16.33)(PORT = 1521))
    (ADDRESS = (PROTOCOL = tcp)(HOST = 10.1.16.34)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = IWP)
    (SERVER=POOLED)
    (FAILOVER_MODE=
    (TYPE=SELECT)
    (METHOD=BASIC)
    (RETRIES=5)
    (DELAY=3)
    The phpinfo() look like this:
    OCI8 Support enabled
    Version 1.3.4
    Revision $Revision: 1.269.2.16.2.38.2.20 $
    Active Persistent Connections 1
    Active Connections 1
    Oracle Instant Client Version 11.1
    Temporary Lob support enabled
    Collections support enabled
    Directive Local Value Master Value
    oci8.connection_class IWPAPP IWPAPP
    oci8.default_prefetch 100 100
    oci8.events On On
    oci8.max_persistent -1 -1
    oci8.old_oci_close_semantics Off Off
    oci8.persistent_timeout -1 -1
    oci8.ping_interval -1 -1
    oci8.privileged_connect Off Off
    oci8.statement_cache_size 20 20
    I am using the instant client for 11g
    Any ideas?
    Thanks!
    Michal

    Don't forget to use oci_free_statement($s); See "Closing Oracle Connections" in The Underground PHP and Oracle Manual. (I was just simplifying this example today for the next release of the manual).
    You may also see the "dedicated optimization", where a pooled server in a non- maxed-out pool is retained (unless needed by another PHP process) under the assumption that the initial PHP process might become active again. See http://www.oracle.com/technology/tech/php/pdf/php-scalability-ha-twp.pdf
    Feel free to email me offline (see my profile) if there are questions/data you don't want to post.
    cj
    Edited by: cj2 on Oct 16, 2008 8:12 AM

Maybe you are looking for

  • UK Payroll Query

    Hi, I need to pull out few PERNRs from diffrent payroll areas whose hiring date is 01.04.2013 and Retroactive accounting must be done for them after April 2013. Plese help

  • Problems signing in to PSE/PRE Forum and Customer Service

    Hello-I am presently  running PSE/PRE8 on a win8 computer with 12GB memory and1TB HDD. I am searching for information on PSE/PRE12. However, I am having problems with my PW/ID. I understand that Photoshop.com has been eliminated and this is the sourc

  • Disable the save option in axAcroPDF1 control in c# winforms

    In my c# winform application i want to display pdf in axAcroPDF1 control.I am able to do that.But i dont want the save option.Any body knows how to disble the save option in axAcroPDF1 control...????

  • Quicktext or Shorthand text in mail

    Are there any applications anyone knows to create shorthand or quick text responses in mail? I would like to be able to do quick replies like Example: "Hi [name of sender] thanks for the tip!" (etc..) Thanks! McBook   Mac OS X (10.4.8)   2GHz

  • DISPLAY PAST YEAR ON REPORT DESIGNER

    Hi Guys I Need To display the actual and past year of entry in the header of a report. For Example, if the user entry it's year 2008, in the header of my report i have to display YEAR 2008 & 2007. im using the Report Designer. can somebody help me  h