jalperin
jalperin

Reputation: 2674

Why is mysqli_query being evaluated as boolean instead of result set

What should be a simple mySQL call from PHP is generating the mySQL error mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

Here's the code:

$updateSQL = "UPDATE content SET type='type1', updated_by='Fred', date_updated = NOW() WHERE id=123";

$mysqli = mysqli_connect($hostname, $username,password, $database);

$update = mysqli_query($mysqli, $updateSQL) or die(mysqli_error($mysqli));
$row_update = mysqli_fetch_assoc($update);
$totalRows_update = mysqli_affected_rows($mysqli);

At first I thought the problem was the or die(mysqli_error($mysqli)), but I get the same error even if I comment that part out. When I check $update with gettype($update), it does show a type of boolean, but I don't understand why.

BTW, the update query itself seems to execute with no problems.

Upvotes: 0

Views: 313

Answers (1)

Emilio Gort
Emilio Gort

Reputation: 3470

Since you are not returning a recordset in you query you don't have to fetch any result, My advice is remove $row_update = mysqli_fetch_assoc($update); line

Upvotes: 1

Related Questions