I have that piece of code in my php file (correctly working):
$db = new Database();
$stmt = $db->prepare("SELECT * FROM bills WHERE group_id=:gid");
$stmt->bindValue(":gid", $_SESSION['group_id'], SQLITE3_INTEGER);
if (($result = $stmt->execute()) === false) {
echo "bad";
}
$bills = $result;
while ($bill = $bills->fetchArray()) {
do stuff....
}
Then I try to put all database related code in function:
function getBillsByGID($gid) {
$db = new Database();
$stmt = $db->prepare("SELECT * FROM bills WHERE group_id=:gid");
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
if (($result = $stmt->execute()) === false) {
return null;
}
return $result;
}
And in the original file:
$bills = getBillsByGID($_SESSION['group_id']);
while ($bill = $bills->fetchArray()) {
do stuff...
}
That gives me message: "Warning: SQLite3Result::fetchArray(): The SQLite3Result object has not been correctly initialised in line 61"
(line with while($bill = $bills->fetchArray()
))
var_dump($bills)
after calling the function gives object(SQLite3Result)#10 (0) { }
So how do I make a function which will work properly?