Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2011
    Posts
    34

    Unanswered: Write array to Oracle table in PHP

    Hi Guys,

    I'm a database analyst who is trying to dump data into my database using PHP for the first time. Here is a snippit of the code I am trying to fix, I know the array $theFinalRow has the correct data because I am also dumping the array to a csv file and it works perfect. Can anyone help with the SQL insert line? it doesn't seem to be passing any data and im not sure if its a syntax thing or what...



    ...
    //connect to database
    $conn = oci_connect('user', 'pass', 'MYDB');

    if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
    }
    //write data to csv file and database, 1 row at a time
    foreach($aryDataComplete as $theFinalRow) {


    $stid = oci_parse($conn, 'INSERT INTO TEST (DT,WEB_CHANNEL,DAILY_UNIQUE_VISITORS,VISITS,PAGE_ VIEWS,ACCOUNTS_CREATED,LOGIN_SUCCESS)
    values ('.$theFinalRow[0].' , '.$theFinalRow[1].' , '.$theFinalRow[2].' , '.$theFinalRow[3].' , '.$theFinalRow[4].' ,'.$theFinalRow[5].' ,'.$theFinalRow[6].')');
    oci_execute($stid);

    fputcsv($csv_reportExport,$theFinalRow); //write to csv
    }
    fclose($csv_reportExport);#close csv file to complete the write process
    oci_close($conn); // close database
    - Using Oracle 11g with Toad v12

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what error message, if any are you getting when you try to execute the SQL. that error could be within the PHP or within the oracle connection library
    what error_reporting level within PHP have you set
    are any of your columns alpha, or are they all numeric. if alpha they will need delimiting appropriately.

    what is the return value from the oci_execute stateemnt, shoudl be true ofr OK, false if there is an error in the statement
    http://php.net/manual/en/function.oci-execute.php

    if false then examining the oci_error shoudl return the most recent error in the oracle connection
    http://php.net/manual/en/function.oci-error.php
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Print out the value of $stid prior to execute. Then run the resulting SQL directly against the database. What happens?
    George
    Home | Blog

  4. #4
    Join Date
    May 2014
    Posts
    24
    May I know if this question is resolved because I am also experiencing the same problem.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hi robherr, if you share your code along with any error messages (and equivalent output of the SQL text) we can see if we can help you.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •