I have recently updated the PHP on my server to 5.4 and I was going through my code updating it to match. When I got to the point of upgrading my database queries I began having problems that I cannot solve. Everything worked before and all I have been changing about the SQL is the procedural call function names. For example:
$stmt = mysqli_prepare($mysqli, “SQL query”);
now becomes,
$stmt = mysqli_stmt_init($mysqli);
mysqli_stmt_prepare($stmt, $sqlReq);
$sqlReq = "SQL query";
I have gone through many forms of error checking and now know that,
mysqli_stmt_prepare($stmt, $sqlReq);
is returning “false” so I get the error:
Warning: mysqli_stmt_bind_param(): invalid object or resource mysqli_stmt in /file/location/
for the bind parameters. In the code below I have removed the error checking because I know that it will fail any error checking but I don’t understand why. So what I am asking is, what am I doing wrong with the new mysqli for PHP 5.4
$mysqli = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
$sqlReq = "SELECT * FROM table_name WHERE column_name = ?";
$stmt = mysqli_stmt_init($mysqli);
mysqli_stmt_prepare($stmt, $sqlReq);
mysqli_stmt_bind_param($stmt, "s", $variable0);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $variable1, $variable2, $variable3);
mysqli_stmt_close($stmt);
mysqli_close($mysqli);