PHP, Oracle and bind variables

From: Jack van Zanen <>
Date: Tue, 29 Jul 2008 12:20:17 +1000
Message-ID: <>

Hi List

I am trying to load data from a file into an oracle table. the file is in matrix format (rows is timestamp and columns are sids where the value is a status) and needs to be put into the table as rows as the number of columns is variable in time
so the layout of the table is

dbname varchar2(20)
timestamp varchar2(20) ---> this I would like to change to date status varchar2(6)

I have created a little code that loops through the files and the data in the files and inserts the data into a table. the first row contains the sids and should not be loaded, but just used in every insert.


function insert_OLA_data_2($file_in)
global $conn, $FileDir; //define variables as global
$lines = file($FileDir.$file_in,FILE_IGNORE_NEW_LINES |
$stmt = oci_parse ($conn,"insert into OLA_DATA2(DBNAME,TIMESTAMP,STATUS)
values (:dbs,:datum,:stat)");
foreach ($lines as $line_num => $line)
if ($line_n < 1 )

$a_line=explode (',',rtrim($line));

for ($item_num=0;$item_num < count($a_line)-1; $item_num++) {


$e = oci_error($stmt);

if(count($e) > 1)
log_message('Error while loading file '.$file_in.'('.$e['message'].')');

$line_n=$line_n + 1;

$commited = oci_commit($conn);

log_message('File '.$file_in.' processed'); }//EoF insert_OLA_data_2

I am using bind variables as there are many executions of the same query with different values.

Above code works fine, but the date is going into the database as a varchar and I would really like it to go in as a date Anyone done this and can point me in the right direction?

format for the string containing the date is 2008:07:29:12:15:00

J.A. van Zanen

Received on Mon Jul 28 2008 - 21:20:17 CDT

Original text of this message