NULL value when returning an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ericm
Forum Newbie
Posts: 17
Joined: Tue Aug 26, 2008 8:33 am

NULL value when returning an array

Post by ericm »

My function queries an oracle database and pulls all corresponding results using the oci_fetch_all function. This function takes several parameters, one of which is a variable to output the data as an array (in my case, given the parameters I've passed in, it's an associative array).

Attempting to return this array, however, gives me a NULL value. I can var_dump the contents of the array and all of the database records are displayed on screen. I read that array parameters can be returned, no problem. Cool, so I want to return this results array (stored in the variable $result). But on the receiving end, I am left with a NULL value.

Code: Select all

 
 
class DB()
{
    function fetch()
    {
        // Get the results from oci_fetch_all.  Results are stored in $results.
        return $results;
    }
}
 
$s = new DB();
$x = $s->fetch("sql query here");
var_dump($x); gettype($x);  // both return NULL
 
 
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: NULL value when returning an array

Post by andyhoneycutt »

Code: Select all

//This returns a value:
var_dump($s->fetch("sql query here"));
//But this doesn't?
$x = $s->fetch("sql query here");
var_dump($x); gettype($x);  // both return NULL
-Andy
ericm
Forum Newbie
Posts: 17
Joined: Tue Aug 26, 2008 8:33 am

Re: NULL value when returning an array

Post by ericm »

andyhoneycutt wrote:

Code: Select all

//This returns a value:
var_dump($s->fetch("sql query here"));
//But this doesn't?
$x = $s->fetch("sql query here");
var_dump($x); gettype($x);  // both return NULL
-Andy
Found my very stupid mistake...
Post Reply