Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Can't get a value in my $variable

Re: Can't get a value in my $variable

From: Mladen Gogala <gogala_at_sbcglobal.net>
Date: Sun, 09 Apr 2006 20:37:17 GMT
Message-Id: <pan.2006.04.09.20.37.18.391288@sbcglobal.net>


On Sun, 09 Apr 2006 16:42:48 +0200, Dave wrote:

> Hello everyone,
>
> I am trying to get the result of a query in a php variable
> I wander what's wrong with this code because I don't get a value in $val, I
> am sure my select is correct as it returns a value in SQL worksheet for
> instance.
>

I don't have fruity tables, but here is your example, modified to use scott/tiger:

#!/usr/local/bin/php
<?php

$con=oci_connect("scott","tiger","LOCAL");

$sql="select ename from emp";

$stmt=oci_parse($con,$sql);
oci_execute($stmt,OCI_DEFAULT);
while( oci_fetch($stmt)) {

     $val=oci_result($stmt,1);
     print("Value=$val\n");
}     

oci_free_statement($stmt);
?>

There are two minor flaws in your program:

  1. oci_result starts counting columns from 1, not from 0.
  2. OCI_DEFAULT should be spelled in capital letters or it want be recognized.

Have a good weekend.

-- 
http://www.mgogala.com
Received on Sun Apr 09 2006 - 15:37:17 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US