This function is supposed to return false when it fails, but in my case it isn’t returning anything, instead it crashes.
echo "This gets printed" ;
$x = $db->query( "SELECT * FROM something WHERE id=123 AND name='abc'" );
echo "This does not get printed";
now if I echo the actual query string, copy paste it into mysql from the command line, it is a valid query. The only thing I can think of is that it might have to do with the fact that it is a recursive query, and it might be invalid to call $db->query twice in a row. Here is more or less my flow:
function recursiveQuery ( $result )
{
$temp = array ();
while ( $row = $result->fetch_assoc() )
{
$temp [ 'name' ] = $row [ 'name' ];
$id = $row [ 'id' ];
$temp [ 'sub' ] = recursiveQuery ( $db->query( "SELECT * FROM something WHERE parent_id=$id" ));
}
return $temp;
}
recursiveQuery ( $db->query( "SELECT * FROM something WHERE parent_id=0" ));
Is this not valid? How should I reorganize it?
Wow, I am such a fool. Turns out, the problem was scope, namely,
$dbwas not accessible from inside recursive query