Fatal error: Call to a member function bind_param() on bool
Fatal error: Uncaught Error: Call to a member function bind_param() on boolShort answer
mysqli::prepare() returns false when the statement cannot be prepared, so $stmt is false and the next call to bind_param() fails. The real error is in the prepare step, not bind_param. Turn on mysqli exceptions, read the message, then fix the SQL: a typo, a missing table, a placeholder used for a name, or two statements.
Fix it fast
1Find out which cause you have
Make mysqli throw on failure, and wrap the prepare call. The exception message from the server is the real cause.
<?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); try { $stmt = $mysqli->prepare("SELECT id FROM users WHERE email = ?"); } catch (mysqli_sql_exception $e) { echo $e->getMessage(); }2Match what you see, then jump to its fix
- 1
No exception and no warning; $stmt is simply falseError reporting is off, so prepare() fails silentlyFix - 2
The exception names an unknown table or column, or a syntax error near a given wordThe SQL itself is invalid for this databaseFix - 3
The exception shows a syntax error right at the place where the ? sitsA ? placeholder is used for a table or column nameFix - 4
The query contains a semicolon followed by another statement, for example a SET before a SELECTThe string holds more than one statementFix
- 1
What does the error look like?
Fatal error: Uncaught Error: Call to a member function bind_param() on boolCall to a member function bind_param() on boolean
Cause 1 of 4
Error reporting is off, so prepare() fails silently
1Check
The manual says prepare() returns false on error. Since PHP 8.1 the default report mode throws mysqli_sql_exception, so on 8.1 and later this fatal usually means reporting was switched off in code or config. Older PHP versions defaulted to off.
php -v | head -n 1
grep -rn "mysqli_report\|report_mode" . --include=*.php | head2Fix
Turn reporting on once, right before you connect. In production, log the exception instead of printing it.
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli($host, $user, $pass, $db);3Verify
A bad query now throws mysqli_sql_exception with the server's message.
php your-script.phpConfirmed by php.net
Cause 2 of 4
The SQL itself is invalid for this database
1Check
A prepared statement is parsed by the server when you call prepare(). A wrong table name, column name or syntax fails right there, and mysqli returns false.
mysql -e "SHOW TABLES" my_db
mysql -e "SHOW COLUMNS FROM users" my_db2Fix
Run the exact SQL string in a MySQL client, fix the name or syntax it complains about, and keep the database name in your connection the same as the one you tested.
$stmt = $mysqli->prepare("SELECT id FROM users WHERE email = ?");
$stmt->bind_param('s', $email);
$stmt->execute();3Verify
prepare() returns a mysqli_stmt object, and execute() returns true.
php your-script.phpConfirmed by php.net
Cause 3 of 4
A ? placeholder is used for a table or column name
1Check
The manual says markers are legal only for values, such as in a VALUES() list or a WHERE comparison, and are not permitted for identifiers such as table or column names.
grep -rn 'FROM ?\|ORDER BY ?\|SET ? ' --include=*.php . | head2Fix
Bind only values. Pick table or column names from a fixed list in your code and write them into the string.
$allowed = ['name', 'created_at'];
$col = in_array($sort, $allowed, true) ? $sort : 'name';
$stmt = $mysqli->prepare("SELECT id FROM users ORDER BY `$col`");3Verify
prepare() no longer returns false.
php your-script.phpConfirmed by php.net
Cause 4 of 4
The string holds more than one statement
1Check
The manual says the query must consist of a single SQL statement.
grep -rn 'prepare("[^"]*;[^"]*")' --include=*.php . | head2Fix
Run each statement in its own call. Use query() for the ones without parameters.
$mysqli->query("SET time_zone = '+00:00'");
$stmt = $mysqli->prepare("SELECT id FROM users WHERE email = ?");3Verify
Both calls succeed.
php your-script.phpConfirmed by php.net
How do I stop it coming back?
- Call mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT) at the start of every request.
- Bind values only; build names from fixed lists.
- Test new SQL in a database client first, with the same account the app uses.
- Keep the number of ? marks equal to the length of the types string in bind_param.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Back end
Fatal error: Call to a member function prepare() on null in PHP
Warning: Undefined variable $conn
The variable you call prepare() on holds null, so the database object was never available at that line.
3 causes, each with a fixBack end
CodeIgniter 4: try/catch does not catch a failed insert in the model
DatabaseException
CodeIgniter throws a DatabaseException on a failed query only when DBDebug is true, and inside a transaction it does not throw unless you ask.
3 causes, each with a fixBack end
CodeIgniter 4 where() builds a different condition than you meant
A SQL syntax error that appears only when a value contains a quote character
The query builder joins every where() with AND and every orWhere() with OR, with no brackets.
3 causes, each with a fixBack end
Call to undefined function mysql_pconnect() after a PHP upgrade
Call to undefined function mysql_connect()
The old mysql_* functions belonged to the ext/mysql extension, which PHP removed in version 7.0.
2 causes, each with a fixBack end
CodeIgniter cannot connect to the MySQL database server
Unable to connect to your database server using the provided settings.
CodeIgniter only reports that its connection failed.
4 causes, each with a fixBack end
Laravel insert fails with 'Field user_id doesn't have a default value'
The insert works when the column is removed or made nullable
Error 1364 means Laravel sent an INSERT without a value for a NOT NULL column that has no default, and MySQL strict mode refuses it.
3 causes, each with a fix