Oracle question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Morten
Forum Newbie
Posts: 1
Joined: Fri Mar 05, 2004 4:38 am

Oracle question

Post 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]
sam2004
Forum Newbie
Posts: 6
Joined: Wed Mar 17, 2004 1:33 pm

Post 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!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
Post Reply