-1

I keep getting the following warning:

[04-Dec-2014 06:51:49 UTC] PHP Warning:  mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in xxx.php on line 48
[04-Dec-2014 06:51:49 UTC] PHP Warning:  mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in xxx.php on line 49
[04-Dec-2014 06:51:49 UTC] PHP Warning:  mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in xxx.php on line 50

In my (limited) experience, this means the MYSQL query I've inputted is wrong. However, I've checked my code -- it works, yet sometimes it throws this error. What is going on? Relevant code is below.

            $stmt = mysqli_prepare($con, "UPDATE xxx SET yyy = ?, zzz = ?, timecheck = NOW(), aaa = ? WHERE bbb = '$ccc'");
            mysqli_stmt_bind_param($stmt, "dss", $abc, $def, $ghi);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_close($stmt);

$abc is a float, $def is NULL, and $ghi is a string. Could the issue be that $ccc is sometimes not holding the value it is supposed to?

Help, please!

2 Answers2

1

As per definition the line

$stmt = mysqli_prepare($con, "UPDATE xxx SET yyy = ?, zzz = ?, timecheck = NOW(), aaa = ? WHERE bbb = '$ccc'");

can return false in error case (see definition here http://php.net/manual/de/mysqli.prepare.php)

Your code is not considering that case. As all your other used mysqli functions expect a mysqli_stmt Object you get those errors.

You should use code like this:

$con = mysqli_connect("host", "user", "pw", "database");

/* check connection */
if (mysqli_connect_errno())
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($stmt = mysqli_prepare($con, "UPDATE xxx SET yyy = ?, zzz = ?, timecheck = NOW(), aaa = ? WHERE bbb = '$ccc'"))
{
    mysqli_stmt_bind_param($stmt, "dss", $abc, $def, $ghi);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
}

mysqli_close($con);
Fabian S.
  • 2,441
  • 2
  • 24
  • 34
  • Your code helps avoid the error but it doesn't solve the issue of why the error is occurring in the first place. – user3210369 Dec 04 '14 at 07:13
  • Thats true. U said "However, I've checked my code -- it works, yet sometimes it throws this error" which means it does only fail some times which makes me think it could be a connection problem. Youll see those errors with my code so you can consider where the error occurs. Having that knowledge it should be easy to fix. Check if you get an output frm the printf line. If not theres something wrong with your query itself. – Fabian S. Dec 04 '14 at 07:16
0

mysqli_prepare() returns a statement object or FALSE if an error occurred.check whether $stmt is assigned false.