When I run the following code:
$_1= $Var->prepare("SELECT Status FROM UserCompletion WHERE `UserID`=?");
$_1->bind_param('i', $_SESSION['UID']);
$_1->execute();
$metaResults = $_1->result_metadata();
$fields = $metaResults->fetch_fields();
I get this error:
Fatal error: Call to a member function fetch_row() on a non-object in /var/www/CMS/API/Constants.php on line 17
This query is on a different page to the one which i'm working on.. This query is:
$PathLocation = $STD->query("SELECT PathLocation From SiteVariables");
$FilePath = $PathLocation->fetch_row();
When I Comment out the execute();
it stops returning that error; why is me having an execute causing a crash on another page?
Update
The execute();
query is not failing.
$_1 = $STD->prepare("SELECT Status FROM UserCompletion WHERE `UserID`=?");
$_1->bind_param('i', $_SESSION['UID']);
$_1->execute();
$metaResults = $_1->result_metadata();
$fields = $metaResults->fetch_fields();
#$GetCompletedArray = $GetCompletedResults->fetch_array(MYSQLI_ASSOC);
print_r($fields);
Returns:
( [0] => stdClass Object ( [name] => Status [orgname] => Status [table] => UserCompletion [orgtable] => UserCompletion [def] => [db] => SLMS [catalog] => def [max_length] => 0 [length] => 1 [charsetnr] => 63 [flags] => 36865 [type] => 3 [decimals] => 0 ) )
and my other query does not fail until the execute is put in place. I know this, because without the query on constants.php, every page the user visits will be blocked.
From the MySQLi execute() manual;
Note:
When using mysqli_stmt_execute(), the mysqli_stmt_fetch() function must be used to fetch the data prior to performing any additional queries.
Your included code isn't doing that, it's only fetching metadata, so the query is most likely leaving an open result set or cursor which makes your second statement fail.