I'm trying to select data from a table and update it at the same time. I'm using multiple prepared statements like this:
mysqli_begin_transaction($link);
mysqli_autocommit($link, FALSE);
$getData = mysqli_prepare($link, "select * from tableA where MID=? and IsRead=0");
mysqli_stmt_bind_param($getData, 'i', $_GET['sid']);
if(!mysqli_stmt_execute($getData))
{
$errorOccurred = true;
}
$getData = mysqli_store_result($link);
mysqli_stmt_close($getData);
$updateIsRead = mysqli_prepare($link, "update tableA set IsRead=1 where MID=?");
mysqli_stmt_bind_param($updateIsRead, 'i', $_GET['sid']);
if(!mysqli_stmt_execute($updateIsRead))
{
$errorOccurred = true;
}
mysqli_stmt_close($updateIsRead);
//commit or rollback
if(!$errorOccurred)
{
mysqli_commit($link);
}
else {
mysqli_rollback($link);
}
while($dataArray = mysqli_fetch_assoc($getData))
{
echo $dataArray['Text'].'<br>';
}
However, I'm getting this warning: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ...
I checked the manual and found nothing wrong with my code or the data set.
Is there a problem in my code that I'm not aware of?