Page 1 of 1
Fetching numbers from a database
Posted: Tue Jun 18, 2002 3:19 pm
by toppac
I am trying to fetch a number from a databse. I have a field that is set to either 1 or 0. I can set the values fine but when I try pull the values back I get null. My code looks like this
Code: Select all
OCIFetchInto($statement, $rc, OCI_ASSOC);
$prodgroup = $rcї'PRODGROUP'];
$groupname = $rcї'GROUPNAME'];
$site = $rcї'SITE'];
$infomerical = $rcї'INFOMERCIAL'];
echo $infomercial." test";
the echo doesnt print anything. There are values in the DB for the field 'INFOMERCIAL', but it wil not get them. Any ideas?
Posted: Tue Jun 18, 2002 5:44 pm
by calebsg
Could all your values be equal to 0, hence the consistent return of a null value?
Ummm.......
Posted: Wed Jun 19, 2002 12:05 am
by BDKR
Hi,
As a way of testing, did you try to echo the info right out of the returned array.
Something like....
Code: Select all
OCIFetchInto($statement, $rc, OCI_ASSOC);
$prodgroup = $rcї'PRODGROUP'];
$groupname = $rcї'GROUPNAME'];
$site = $rcї'SITE'];
$infomerical = $rcї'INFOMERCIAL'];
# Now echo for testing
echo $rcї'INFOMERCIAL']."test";
# The old way
# echo $infomercial." test";
I'm assuming this is Oracle. Before this code, are you using OCIparse()? If so, are you testing that $statement doesn't equal false?
Perhaps something like:
Code: Select all
if( ($statement = OCIparse($conn, $query)) != false )
{ /* Insert your code here */ }
Now eventhought this may look good, and the manual says OCIparse() will return false on failure, there are those that say it allways returns true. I don't know one way or the other, but the nay sayers suggest using OCIerror() as well. You may wish to check this out in the manual.
Remember, the manual is your friend. (A lot nicer than RTFM)
And lastly, why take the extra step of assigning to vars each element of the associative array? I agree that there are at times good reasons for this; I just thought I'd ask.
later on and hope that helps,
BDKR (TRC)
Posted: Wed Jun 19, 2002 8:34 am
by toppac
Yes some of the values are equal to 0, but some are also equal to 1, which is still returning null. The database field is supposed to hold 1 or Null. When I check the database it has a value in it, but that value will not get returned.
The variables are actually global vars, i have to use them in other functions. I just did not want to type out $_POST[] each time

Posted: Wed Jun 19, 2002 9:43 am
by toppac
Fixed it. It was a damn typo. I had $infomerical instead of $infomercial. Sorry to waste everyones time, gonna go pull my hair out some more.
