Oci_bind_by_name

Hi to all,
Can anyone explain how to use of oci_bind_by_name in more detail?
for example oci_bind_by_name(":oracle_parameter",$php_var, $maxlength [, int $type])
how do you specify the maxlength? what criteria to consider
what can you specify in $type? how do you use the $type ( actually i m more confused on this part)
what is the advancetage of using the oci_bind_by_name and how do you use these function
in my case oracle statement of mine is
$stmt = "select column1, column2 from (select column1, column2, row_num rnum from (select column1, column2 from table1) where row_num < :lastrow) where rnum> :firstrow";
$connection= oci_connect('hr', 'hr', 'orcl');
$q =oci_parse($connection, $query);
oci_bind_by_name ($q, ":firstrow" , 1); //is this possible?? because the it is bind to a number
oci_bind_by_name ($q, ":lastrow" , 1000); //??
oci_execute($q);
$q will be the array of your table blah blah.........
if you intend have the same page over and over again but just having row number change how would you use the oci_bind_by_name? do your php_page call the oci_connect again and do the binding for the page like the code above? how do you guys do to save some oracle resources...
by the way, i have also notice that if you perform a "order by" in the oracle query it does take some time...how to reduce this time..any recommendation?
thanks...
Message was edited by:
Jo Ee

Hi,
Best source of info is PHP Manual: http://www.php.net/function.oci_bind_by_name
1. how do you specify the maxlength? what criteria to consider
"Sets the maximum length for the bind. If you set it to -1, this function will use the current length of variable to set the maximum length."
For input parameters you can use -1 (it's easy but can cause problems with scalability, as different values causes to create new child cursor in SGA. It's better to estimate what is your max and set it)
For output variables you have to set buffer length - what is the max length that can be returned from DB.
2.what can you specify in $type?
It can be one of:
#SQLT_FILE - for BFILEs;
#SQLT_CFILE - for CFILEs;
#SQLT_CLOB - for CLOBs;
#SQLT_BLOB - for BLOBs;
#SQLT_RDD - for ROWIDs;
#SQLT_NTY - for named datatypes;
#SQLT_INT - for integers;
#SQLT_CHR - for VARCHARs;
#SQLT_BIN - for RAW columns;
#SQLT_LNG - for LONG columns;
#SQLT_LBI - for LONG RAW columns;
#SQLT_RSET - for Ref cursosr
Default is SQLT_CHR. You should set proper type, otherwise you will have implicit type conversion.
In your case try:
oci_bind_by_name ($q, ":firstrow" , 1, 10, SQLT_INT);
oci_bind_by_name ($q, ":lastrow" , 1000, 10, SQLT_INT);
3. if you intend have the same page over and over again but just having row number change how would you use the oci_bind_by_name? do your php_page call the oci_connect again and do the binding for the page like the code above?
Well, every page is new request. And for every page you have to obtain persistent connection (oci_pconnect) or create new connection (oci_connect). I recommend using persistent connections. (BTW. in Oracle 11g it is even improved by Database Resident Connection Pooling).
If you use persistent connections and cursors with bind variables, then cursors are kept parsed in session, and when you execute oci_parse existing execution plan is reused.
Regards,
Paweł

Similar Messages

  • Oci_bind_by_name causes query to return null

    I have a bind variable which I use to feed into a where clause. The variable has a value that is a comma delimited string (i.e., 'Smith', 'Jones','Johnson').
    So my query is :
    select * from name where name in (:name).
    where :name = 'Smith', 'Jones','Johnson'.
    This does not return a result.
    Is this an invalid use of oci_bind_by_name. Will it not accept a comma delimited string for a value?

    What you are seeing is not unique to PHP.
    Tom Kyte discusses general solutions in http://www.oracle.com/technology/oramag/oracle/07-mar/o27asktom.html
    Also see http://tkyte.blogspot.com/2006/01/how-can-i.html
    and http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061
    -- cj

  • Invalid identifier results from an sql statement in php

    hello there, i'm trying to access data from an oracle 11g database via oci and php 5.3.8.
    i'm getting the ORA-00904 (invalid identifier) error when executing the following statement:
    $stid = oci_parse($conn, 'select * from table1 where column1 = "XYZ"');
    when i do this:
    $searchstring = "XYZ";
    $stid = oci_parse($conn, 'select * from table1 where column1 = '.$searchstring.'');
    i'm getting this error:
    ORA-00933: SQL command not properly ended
    column1 is varchar2, the entries are either letters and numbers (never only numbers) or empty.
    when i do this:
    $stid = oci_parse($conn, 'select * from table1');
    i'm getting the data and there are entries in column1 with XYZ.
    has anyone an idea, what i do wrong?
    regards j

    The PHP forum for questions like this is at http://www.oracle.com/technetwork/forums/php/index.html
    You really need to be using a bind variable here. Otherwise you will likely suffer from poor DB performance, and also open yourself to SQL Injection security attacks. Try:
    $stid = oci_parse($conn, 'select * from table1 where column1 = :bv');
    oci_bind_by_name($stid, ":bv", $searchstring);Regarding quoting of your example try:
    $searchstring = "XYZ";
    echo  'select * from table1 where column1 = '.$searchstring.'';Then run that SQL in SQL*Plus and watch it fail. What you need is given with:
    echo  'select * from table1 where column1 = \''.$searchstring.'\'';See the bottom of p 126 of The Underground PHP and Oracle Manual
    Note that with the bind variable example you didn't need quotes around :bv.

  • Trying to pass array to stored procedure in a loop using bind variable

    All,
    I'm having trouble figuring out if I can do the following:
    I have a stored procedure as follows:
    create procedure enque_f826_utility_q (inpayload IN f826_utility_payload, msgid out RAW) is
    enqopt dbms_aq.enqueue_options_t;
    mprop dbms_aq.message_properties_t;
    begin
    dbms_aq.enqueue(queue_name=>'f826_utility_queue',
    enqueue_options=>enqopt,
    message_properties=>mprop,
    payload=>inpayload,
    msgid=>msgid);
    end;
    The above compiles cleanly.
    The first parameter "inpayload" a database type something like the following:
    create or replace type f826_utility_payload as object
    2 (
    3 YEAR NUMBER(4,0),
    4 MONTH NUMBER(2,0),
    83 MUSTHAVE CHAR(1)
    84 );
    I'd like to call the stored procedure enque_f826_utility_q in a loop passing to it
    each time, new values in the inpayload parameter.
    My questions are:
    First, I'm not sure in php, how to construct the first parameter which is a database type.
    Can I just make an associative array variable with the keys of the array the same as the columns of the database type shown above and then pass that array to the stored procedure?
    Second, is it possible to parse a statement that calls the enque_f826_utility_q procedure using bind variables and then execute the call to the stored procedure in a loop passing new bind variables each time?
    I've tried something like the following but it's not working:
    $conn = oci_pconnect (....);
    $stmt = "select * from f826_utility";
    $stid = oci_parse($conn, $sqlstmt);
    $r = oci_execute($stid, OCI_DEFAULT);
    $row = array();
    $msgid = "";
    $enqstmt = "call enque_f826_utility_q(:RID,:MID)";
    $enqstid = oci_parse($conn, $sqlstmt);
    oci_bind_by_name($enqstid, ":RID", $row); /* line 57 */
    oci_bind_by_name($enqstid, ":MID", $msgid);
    while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
    ++$rowcnt;
    if (! oci_execute($enqstid)) /* line 65 */
    echo "Error";
    exit;
    When I run this, I get the following:
    PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
    ine 57
    Entering loop to process records from F826_UTIITY table
    PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
    ine 65
    PHP Warning: oci_execute(): ORA-06553: PLS-306: wrong number or types of argume
    nts in call to 'ENQUE_F826_UTILITY_Q' in C:\Temp\enqueue_f826_utility.php on lin
    e 65
    PHP Notice: Undefined variable: msgnum in C:\Temp\enqueue_f826_utility.php on l
    ine 68
    Error during oci_execute of statement select * from F826_UTILITY
    Exiting!

    Thanks for the reply.
    I took a look at this article. What it appears to describe is
    a calling a stored procedure that takes a collection type which is an array.
    Does anyone from Oracle know if I can pass other database type definitions to a stored procedure from PHP?
    I have a type defined in my database similar to the following which is not
    an array but a record of various fields. This type corresponds to a payload
    of an advanced queue payload type. I have a stored procedure which will take as it's input, a payload type of this structure and then enqueue it to a queue.
    So I want to be able to pass a database type similar to the following type definition from within PHP. Can anyone from Oracle verify whether or not this is possible?
    create or replace type f826_utility_payload as object
    YEAR NUMBER(4,0),
    MONTH NUMBER(2,0),
    UTILITY_ID NUMBER(10,0),
    SUBMIT_FAIL_BY VARCHAR2(30),
    MUSTHAVE CHAR(1)
    );

  • 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.

  • I can access a function in a package using OCI drivers but not PDO drivers

    Hello all, i am a newbie to Oracle and its drivers for PHP. I would like to use PDO, and I have my database activity in packages, which have procedures and functions. My package has overloaded functions and that has been giving me a tough time with these drivers. So one signature of my function get_data contains a four arguments and all four are numbers, while another signature of get_data has the first two as numbers and the next two as varchar2. So when I try to access this function which is part of a package, I am able to retrieve data, and the driver I am using is OCI8, but when I try to do the same with PDO, it does not work. It gives me this error,
    *General error: 6553 OCIStmtExecute: ORA-06553: PLS-307: too many declarations of 'GET_DATA' match this call  (/var/www/php-5.3.3/ext/pdo_oci/oci_statement.c:146)' in /var/www/pdo_check.php:251 Stack trace: #0 /var/www/pdo_check.php(251): PDOStatement->execute() #1 /var/www/pdo_check.php(345): dbPDO->execPackage2() #2 {main} thrown in /var/www/pdo_check.php on line 251 *
    I got this error earlier with OCI drivers, then I added the datatype while binding the values.
    Has anybody had this headache earlier??
    ##Works
    *$qu = oci_parse($connect, 'select pack.get_data(:p1,:p2,:p3,:p4)as rc from dual');
    $p1 = (int)121;
    $p2 = (int)222;
    $p3 = (int)324;
    $p4 = (int)001;
    oci_bind_by_name($qu,":p1",$p1,10,OCI_B_INT);
    oci_bind_by_name($qu,":p2",$p2,10,OCI_B_INT);
    oci_bind_by_name($qu,":p3",$p3,10,OCI_B_INT);
    oci_bind_by_name($qu,":p4",$p4,10,OCI_B_INT);
    oci_execute($qu) or die("did not execute");
    $r = oci_fetch_array($qu);*
    ##Does not work
    *$sql = 'select pack.get_data(:p1,:p2,:p3,:p4) from dual';
    $result = $this->dbConnect->prepare($sql);
    $p1 = (int)2;
    $p2 = (int)2;
    $p3 = (int)2;
    $p4 = (int)6;
    $result->bindParam(':p1', $p1, PDO::PARAM_INT);
    $result->bindParam(':p2', $p2, PDO::PARAM_INT);
    $result->bindParam(':p3', $p3, PDO::PARAM_INT);
    $result->bindParam(':p4', $p4, PDO::PARAM_INT);
    $result->execute();*
    I am still perplexed why is PDO giving me an error, when I have virtually mentioned everything is asks for?

    I think the only person who can really answer this question is Chris Jones. For my money I tend to steer clear of PDO as it is a bit quirky ( at least in my experience ) and it does not support reference cursors.

  • 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

  • File Uploads using stored procedures

    Hello, I'm quite new here, but I have a question that I've been butting my head against for the past day. Here goes.
    We need to upload a file using a stored procedure (PL/SQL procedure.)
    The two things I have found that work are
    1) Having oracle do the file handling (using bfiles) in the procedure
    2) using an insert statement directly to upload the file contents into a blob.
    The platform is php (Oracle instant client) and I will show some code examples.
    1) is unworkable because Oracle will not have direct access to any files.
    2) is fine, but we would prefer to use a procedure so as to abstract what exactly goes on and possibly other operations away from the php and the framework.
    What worked:
    1)
    CREATE OR REPLACE PROCEDURE php_upload_file (file_name in varchar2, canonical_name in varchar2, owner in number, file_id IN OUT number)
    AS
    src_loc bfile:= bfilename('DOC_LOC',php_upload_file.file_name);
    dest_loc BLOB;
    begin
    insert into files values(owner,canonical_name,empty_blob(),files_seq.nextval) returning files.data, files.file_id
    into dest_loc, file_id;
    dbms_lob.open(src_loc,DBMS_LOB.LOB_READONLY);
    DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
    DBMS_LOB.LOADFROMFILE(
    dest_lob => dest_loc
    ,src_lob => src_loc
    ,amount => DBMS_LOB.getLength(src_loc));
    DBMS_LOB.CLOSE(dest_loc);
    DBMS_LOB.CLOSE(src_loc);
    COMMIT;
    end;
    'DOC_LOC' is a directory I've set up that the user has access to.
    Interfacing with PHP this just looks like
    oci_parse($conn,"BEGIN php_upload_file('{$uploadfilename}','{$propername}',{$ownerid},:file_id); END;");
    Dead simple, right?
    I also do a bind command to pull out 'file_id' so I know the id that was just inserted.
    The other solution is
    $contents = file_get_contents($_FILES["uploadedfile"]["tmp_name"]);
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn,
    "INSERT INTO files (employee_id, filename, data, file_id) VALUES(175,'"
    .$_FILES["uploadedfile"]["name"].
    "', empty_blob(), files_seq.nextval) RETURNING file_id, files.data INTO :file_id, :src_contents");
    where :src_contents is binded to a lob and :file_id as before is binded to an INT:
    oci_bind_by_name($stmt, ':src_contents', $lob, -1, OCI_B_BLOB);
    oci_bind_by_name($stmt, ':file_id', $insert_id, -1, SQLT_INT);
    oci_execute($stmt,OCI_DEFAULT);
    In this case the last thing I do before the commit is
    $lob->save($contents);
    Both work fine, but what I need is this
    $contents = file_get_contents($_FILES["uploadedfile"]["tmp_name"]);
    $lob = oci_new_descriptor($conn, OCI_D_LOB);
    $stmt = oci_parse($conn,"BEGIN do_upload_file(:src_contents,'{$propername}',{$ownerid},:file_id); END;");
    oci_bind_by_name($stmt, ':src_contents', $lob, -1, OCI_B_BLOB);
    oci_bind_by_name($stmt, ':file_id', $insert_id, -1, SQLT_INT);
    oci_execute($stmt,OCI_DEFAULT);
    $lob->save($contents);
    oci_commit($conn);
    this omits error conditions (such as on $lob->save ... etc.) it is simplified.
    The content of the procedure I changed as follows, but it seems untestable.
    CREATE OR REPLACE PROCEDURE do_upload_file (src_contents IN OUT blob, canonical_name in varchar2, owner in number, file_id IN OUT number)
    AS
    dest_loc BLOB;
    begin
    insert into files values(owner,canonical_name,empty_blob(),files_seq.nextval) returning files.data, files.file_id
    into dest_loc, file_id;
    dbms_lob.open(src_contents,DBMS_LOB.LOB_READONLY);
    DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
    DBMS_LOB.COPY(dest_lob => dest_loc,
    src_lob => src_contents
    ,amount => DBMS_LOB.getLength(src_contents));
    DBMS_LOB.CLOSE(dest_loc);
    DBMS_LOB.CLOSE(src_contents);
    COMMIT;
    end;
    I don't get errors because I cannot figure out a way to run this procedure in my PL/SQL environment with valid data. (I can run it with a blank blob.)
    But when I work out the order of what's going on, it doesn't make sense; the commit in the procedure is before the $lob->save(...) and thus it would never save the data... nonetheless it should at least create a record with an empty blob but it does not. What is wrong is beyond the error level that seems to be supported by PHP's oci_error function (unless I have not discovered how to turn all errors on?)
    In any case I think the logic is wrong here, but I'm not experienced enough to figure out how.
    To test it I would need to create a driver that loads an external file into a blob, and passes that blob into the procedure. Trouble is, even if I make a blob and initialize it with empty_blob() it treats it as an invalid blob for the purposes of the dbms_lob.copy procedure.
    If someone has solved this problem, please let me know. I would love to be able to do the file upload with just a single procedure.

    Thanks. In my estimation that is exactly the issue. But that doesn't help with a resolution.
    The actual file size: 945,991 bytes
    If Firefox is miscalculating the length (in Safari/Chrome 945991 and 946241 in Firefox), then Firefox is reporting erroneously and should be raised as a bug in Firefox, would you agree?

  • 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.

  • View display image BLOB with PHP!

    I using..
    $consulta = oci_parse($conexao,"select photo from userp where usrph_status = 'A' and id = :didbv");
    $didbv = $_POST["id"];
    oci_bind_by_name($consulta, ':didbv', $didbv);
    oci_execute($consulta, OCI_NO_AUTO_COMMIT);
    while (($row = oci_fetch_array($consulta, OCI_ASSOC)) != false) {
    $arr = oci_fetch_assoc($consulta);
    header("Content-type: image/JPEG");
    $result = $arr['PHOTO']->load();
    print "<img src='".$arr['PHOTO']."'>";
    print $result;
    echo $result;
    What appears in the result page is:
    This image contains errors and can not be displayed.
    How to fix this?

    - With that content type, you should be sending only binary data, not the HTML "<img" text.
    - You have both a print and and echo.
    Look at script 105 on p.236 of The Underground PHP and Oracle Manual | Homepage

  • How to call PL/SQL function from php

    I have one function define in package,like below
    >>
    create or replace package body Intg$Label_DB as
    Future constant date := to_date ('21990101', 'YYYYMMDD');
    Max_Annotation_Len integer := 3995;
    function Get_Tagged_Label (Product_Name varchar2,Branch_Name varchar2, Platform_Name varchar2, Schema_Name varchar2) return varchar2 is
    Series_Id integer := Get_Series (Product_Name,Branch_Name,Platform_Name);
    Schema_Id integer := Get_Schema (Schema_Name);
    Dep_Label_Id integer;
    Next_Dep_Label_Id integer;
    Result_Id integer;
    Result Intg$Labels.Name%type;
    begin
    select SLT.Dep_Label_Id, SLT.Next_Dep_Label_Id into Dep_Label_Id, Next_Dep_Label_Id
    from Intg$Series_Label_Tags SLT
    where SLT.Series_Id = Get_Tagged_Label.Series_Id and SLT.Schema_Id = Get_Tagged_Label.Schema_Id;
    Result_Id := Next_Dep_Label_Id;
    if Result_Id = -1 then
    Result_Id := Dep_Label_Id;
    end if;
    select L.Name into Result from Intg$Labels L where L.Id = Result_Id;
    return Result;
    exception
    when NO_DATA_FOUND then
    return '';
    end Get_Tagged_Label;
    >>
    i want to call Get_Tagged_Label() from php and print the output,I tried below code but seems i am missing lots of things here.Any help will be appreciate.
    $sql = 'BEGIN INTG$Label_DB.Get_Tagged_Labell(:Product_Name,:Branch_name,:Platform_Name,:message,:message_1,:message_2); END;';
    $stmt = oci_parse($conn,$sql) or die ('Can not parse query') ;
    // Bind the input parameter
    oci_bind_by_name($stmt,':Product_Name',$name,32);
    oci_bind_by_name($stmt,':Branch_name',$branch,32);
    oci_bind_by_name($stmt,':Platform_Name',$pt,32);
    // Bind the output parameter
    oci_bind_by_name($stmt,':message',$message,32);
    oci_bind_by_name($stmt,':message_1',$message_1,32);
    oci_bind_by_name($stmt,':message_2',$message_2,32);
    // Assign a value to the input
    $name = 'PCBPEL';
    $branch ='MAIN';
    $pt ='GENERIC';
    oci_execute($stmt);
    Thanks
    Hridyesh

    What errors are you getting?
    It's always helpful to know the version of PHP and the database.
    When calling a function, you'll need a bind variable to hold the return value, and make sure the number of parameters match:
    $sql = 'BEGIN :rv := INTG$Label_DB.Get_Tagged_Labell(:Product_Name,:Branch_name,:Platform_Name,:message); END;';
    This new variable will need to bound with oci_bind_by_name()
    Have you looked at my free Underground PHP and Oracle Manual at http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf ? Or any one of the other fine PHP-Oracle books available?

  • Trying to understand oci8 refcursor bits

    Hi
    I have been using ADOdb for a while and sort of not thinking too much about it, but sort of trying to get some of the stuff. Perhaps I think too much like my old C programming daze and wonder about things that I should not. With that in mind I was reading and working through some of the examples in the underground php oracle manual and came across this example:
    <?php
    $c = oci_connect('hr', 'hrpwd', 'localhost/XE');
    // Excute the call to the PL/SQL stored procedure
    $s = oci_parse($c, "call myproc(:rc)");
    $refcur = oci_new_cursor($c);
    oci_bind_by_name($s, ':rc', $refcur, -1, OCI_B_CURSOR);
    oci_execute($s);
    // Execute and fetch from the cursor
    oci_execute($refcur); // treat as a statement resource
    echo "<table border='1'>\n";
    while($row = oci_fetch_array($refcur, OCI_ASSOC)) {
    echo "<tr>";
    foreach ($row as $c) {
    echo "<td>$c</td>";
    echo "</tr>\n";
    echo "</table>\n";
    ?>
    and I have a few questions if someone can answer them.
    $c in this example holds the "handle" to the database connection ... a kind of pointer I assume
    then we store in $refcur the result of oci_new_cursor() which is called with the connection variable returned from the call to oci_connect()
    strangely when I print_r ($c) I just get something like:
    Resource id #1
    so I wonder just what I've got there ....
    the next question is what is going on in the for loop there? We say:
    foreach ($row as $c)
    which (as far as I know) will overwrite $c ... will this not result in us loosing our DB connection?
    if so, why structure it this way? economy of variables??
    I assume that this will also mean that I will not be able to make any subsequent database operations (like oci_parse a new cursor
    Edited by: finophile on Sep 2, 2010 10:47 PM

    "Handle" is Oracle's C level name for some of the data structures used inside the PHP OCI8 extension. In PHP the (roughly) equivalent name is "resource". The connection resource/handle is the data structure that holds internal state of the connection to the database that wouldn't make sense for the PHP program to know about.
    The reuse of $c in this example was pointed out to me a while back. Yes it will lose PHP's access to the connection. It's not intentional. I believe I was flip-flopping on whether to use $conn or $c for the connection resource in all examples. Here I ended up with $c being used for "connection" and for "column".
    The UGP&OM is out of date regarding REF CURSOR performance. See http://blogs.oracle.com/opal/2009/09/oracle_database_11gr2_enhancem.html for the current information.

  • Calling stored procedure with php

    I'm trying to call a stored procedure through php but keep getting the error message Fatal error: Call to undefined function: oci_bind_by_name()
    The code I have written so far is (:v_staff_id is an in parameter and the other two are outs) :
    $staff_id = $_POST["staff_id"];
    $query = "begin bonus( :v_staff_id,:value,:percent );end;";
    $v_staff_id = $staff_no;
    $stmt = ociparse($conn,$query);
    oci_bind_by_name($stmt,':v_staff_id',$v_staff_id,32);
    oci_bind_by_name($stmt,':value',$value,32);
    oci_bind_by_name($stmt,':percent',$percent,32);
    ociexecute($stmt);
    Any suggestions on how I might get this working would be very much appreciated

    Perhaps you have an older version of PHP? The man page http://us.php.net/manual/en/function.oci-bind-by-name.php points out that in PHP 4 you need to use ocibindbyname().
    However - for your own sake you shouldn't be using the version of OCI8 that comes with older versions of PHP. You can upgrade pretty quickly in most cases. See the notes in Re: frustrations with oci_fetch_array()
    -- cj

  • Oracle-PHP PL/SQL Problem

    Dear,
    I have this situation:
    Inside PHP I call this statement:
    $usr_stmt = oci_parse($conn, "begin PKG_USERBEHEER_TEST.user_insert(PKG_USERBEHEER_TEST.user_create_type(:usr_id,:usr_naam,:usr_vnaam,:usr_email,:usr_pass,SYSDATE,NULL),:p_exusr_id); end;");
    binding the variables
    oci_bind_by_name($usr_stmt, ':usr_id', $USR_ID);
    oci_bind_by_name($usr_stmt, ':usr_naam', $USR_NAAM);
    oci_bind_by_name($usr_stmt, ':usr_vnaam', $USR_VNAAM);
    oci_bind_by_name($usr_stmt, ':usr_pass', $USR_PASS);
    oci_bind_by_name($usr_stmt, ':usr_email', $USR_EMAIL);
    oci_bind_by_name($usr_stmt, ':p_exusr_id', $EXEC);
    INSIDE MY PACKAGE:
    FUNCTION user_create_type(usr_id users.usr_id%TYPE, usr_naam users.usr_naam%TYPE, usr_vnaam users.usr_vnaam%TYPE, usr_email users.usr_email%TYPE, usr_pass users.usr_pass%TYPE, usr_start_datum users.usr_pass%TYPE, usr_eind_datum users.usr_eind_datum%TYPE) return user_rec is
    v_rec user_rec;
    Begin
    v_rec.usr_id := usr_id;
    v_rec.usr_naam := usr_naam ;
    v_rec.usr_vnaam:=usr_vnaam;
    v_rec.usr_email:=usr_email;
    v_rec.usr_pass :=usr_pass;
    v_rec.usr_start_datum := usr_start_datum;
    v_rec.usr_eind_datum := usr_eind_datum;
    return v_rec;
    end user_create_type;
    PROCEDURE user_insert(r IN OUT user_rec, p_exusr_id IN users.usr_id%TYPE) IS
    BEGIN
    --check if allowed
    IF(NOT checkallowedactions(p_exusr_id, 117)) THEN
    raise_application_error(-20999, 'User is not allowed executing this action');
    END IF;
    --end check if allowed
    SELECT seq_users.nextval
    INTO r.usr_id
    FROM dual;
    SELECT sysdate
    INTO r.usr_start_datum
    FROM dual;
    INSERT
    INTO users(usr_id, usr_naam, usr_vnaam, usr_email, usr_pass, usr_start_datum)
    VALUES(r.usr_id, r.usr_naam, r.usr_vnaam, r.usr_email, cryptit.encrypt(r.usr_pass), r.usr_start_datum);
    END user_insert;
    When I excecute my statement I get this error:
    Warning: oci_execute() [function.oci-execute]: ORA-06550: line 1, column 39: PLS-00363: expression 'PKG_USERBEHEER_TEST.USER_CREATE_TYPE' cannot be used as an assignment target ORA-06550: line 1, column 7: PL/SQL: Statement ignored in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\add_user.php on line 22
    But I need the out parameter, because I need my generated ID (Sequence) for futher use in my script.
    I'm not able to edit the pl/sql script because an other application is using it.
    Somebody can help me?
    Thx
    Davy

    The call to PKG_USERBEHEER_TEST.user_insert needs to pass a single PL/SQL variable as the first argument so that user_insert can return an update record. The OUT declaration of 'r' in user_insert is throwing the error. To that point, the problem is not due to PHP. You would get the same error in SQL*Plus.
    But, because you can't bind a record in PHP, you need to create a new PL/SQL function that calls PKG_USERBEHEER_TEST.user_create_type putting the returned record into a PL/SQL variable, and then calls user_insert. PHP would call the wrapper PL/SQL function.
    -- cj

Maybe you are looking for

  • How can we delete the data in e-fact table.

    how can we delete the data in e-fact table.

  • Use of generics in the Map interface

    After using Java 1.5 for a while, I've gotten pretty comfortable using generics and the collections framework. Very often, I depend on the new generics-related compiler warnings to guide me when I've made changes to my code. Recently, I missed a fair

  • Trouble Syncing Ipod Touch 2G?

    My daughter has had an Ipod Touch 2G for quite some time now. I sync it with Itunes every few months. I tried during Christmas however the computer is not recognizing it. On the Itunes webpage, it appears that it is now compatable with iOS 4.3.3, and

  • Photoshop CS6 and Yosemite freezing tools!

    Hi i have now upgraded to Yosemite and Photoshop CS6 and gone into melt down. Switching tools and using short cuts is almost impossible or frustrating. To switch from one tool to another will work 1 in 10 times.. you generally need to click something

  • Custom Bapi

    hi folks, can anyone explain as how to create custom BAPI from scratch? In HR there are a lot of standard BAPIs available - Is there any scenario of creating custom BAPI from scratch in HR module. If any info on this.. it would really help. Thanks Vi