Reputation: 167
So , i have this function which returns a result set :
function get_products()
{
global $database;
$statement = 'select * from products';
return $result = $database->query($statement);
}
and i want to call it in other php file like this :
include './DBvalidation.php';
$res = get_products();
$res->fetchAll();
but the method fetchAll() of the return set is not recognized there . what should i modify ?
Upvotes: 0
Views: 42
Reputation: 177
You cant just use the $result
assosiation as return statement (it will just return true
in Your case, which is wrong) use something like this instead :
return $database->query($statement);
You dont even need the $result
variable at all anyway cause its end of function execution and You wont be able to use it elsewhere.
Upvotes: 1
Reputation: 1878
function get_products()
{
global $database;
$statement = 'select * from products';
return $database->query($statement);
}
OR:
function get_products()
{
global $database;
$statement = 'select * from products';
$result = $database->query($statement);
return $result;
}
Upvotes: 1