Page 1 of 1

Oracle question

Posted: Fri Mar 05, 2004 4:38 am
by Morten
Hello!

Im trying to do a script for making select queries to my database. At the moment it looks like this:

Code: Select all

<?php

$results = array();

$statement = ociparse($link, $query);
ociexecute($statement);


  $numCols = ocinumcols($statement);


  $row = array();

  for($i=0; $i<$numCols; $i++)
  {
     $row[ocicolumnname($statement, $i)] = ociresult($statement, $i);
     var_dump($row[ocicolumnname($statement, $i)]);
   }
  array_push($results,$row);

  while(ocifetch($statement)){
   $row = array();
   for($i=0; $i<$numCols; $i++){
     $row[ocicolumnname($statement, $i)] = ociresult($statement, $i);

    }
    array_push($results,$row);
  }

?>
It works perfectly for making queries like "select * from sometable", but when i try to do a query like this:
"select count(*) AS COUNT from sometable where attribute='$attribute'"
it doesnt fill in the array with anything at all... Any suggestions?

Regards
Morten

[Edit: Added PHP tags for eyecandy. --JAM]

Posted: Wed Mar 17, 2004 1:35 pm
by sam2004
Hi Morten,

Your task seems similar to mine(oracle connectivity to php).
Could u please let me know if u have seen this error:
Warning: ocilogon(): _oci_open_server: รด
sample code snippet of yours if possible.....so i can look for bugs in mine..
Thanks so much!

Posted: Wed Mar 17, 2004 7:50 pm
by JAM
Sorry, not to familiar with Oracle issues, but as I thought of it...

Code: Select all

// change...
"select count(*) AS COUNT from sometable where attribute='$attribute'" 
// to...
"select count(*) AS 'COUNT' from sometable where attribute='$attribute'"


A real shot in the dark, but if it helps, great. If not, ignore me. =)
My thought was that the ocicolumnname() function didn't understand the column name if it didn't have the quotes around it...