Error 2031 is returned when a prepared statement is executed without supplying values for all named or positional parameters.
MySQL Error 2031: CR_PARAMS_NOT_BOUND occurs when you run a prepared statement without binding every placeholder. Bind all parameters with the correct data types or remove unused placeholders to resolve the error.
No data supplied for parameters in prepared statement
MySQL throws Error 2031 with the condition name CR_PARAMS_NOT_BOUND when a prepared statement contains placeholders but no matching values are supplied through the client API. The server refuses to execute the statement because it cannot substitute the missing data.
The problem appears in client libraries such as libmysql, JDBC, ODBC, or PHP PDO when developers forget to call the bind function for each parameter or supply an array of incorrect length.
Fixing it is critical to prevent runtime failures and SQL injection risks.
Unbound positional or named placeholders trigger the error immediately after the EXECUTE
call. MySQL checks that the bound parameter count equals the number of ?
or :name
tokens in the prepared statement.
Mismatched data types, NULL-only binds, or conditional logic that skips a binding step also raise Error 2031.
Framework abstractions sometimes silently drop parameters, leading to confusion when the statement finally runs.
Count every placeholder and bind a value before executing. Use language-specific helper methods, array spreads, or named maps to guarantee coverage. Validate parameter arrays at runtime to catch mismatches early.
If a parameter is optional, rewrite the SQL to remove that placeholder or supply a default.
In Galaxy, the editor highlights each placeholder and warns when a bind is missing, making fixes immediate.
Loop-generated INSERT statements often skip the last value; add defensive length checks. Dynamic WHERE clauses with optional filters should use string concatenation or COALESCE defaults instead of leaving gaps.
Batch APIs like JDBC addBatch must call clearParameters between iterations to avoid stale bindings.
Enable driver verbose logging to confirm bind order.
Adopt parameterized helper functions that assert placeholder counts. Unit-test prepared statements with edge-case inputs. In Galaxy, rely on AI copilot autogeneration and live execution plans to catch issues early.
Monitor application logs for Error 2031 spikes and integrate alerting.
Continuous integration pipelines can run dry-run executions with dummy binds to detect missing parameters before deploy.
Error 1210 (ER_WRONG_ARGUMENTS) arises when placeholder data types do not match column types. Error 1064 (ER_PARSE_ERROR) indicates malformed SQL rather than missing binds. The fixes overlap but differ in validation focus.
Client library errors such as PDOException "SQLSTATE[HY093]: Invalid parameter number" map to Error 2031 internally. The mitigation is identical - bind all parameters correctly.
.
It is a client error detected before the query reaches the server, ensuring placeholder safety.
No. You must still bind a value for each placeholder or remove the placeholder entirely.
Galaxy highlights placeholders and counts bound parameters in real time, alerting you before execution.
Error 2031 has existed since MySQL 5.x and continues in 8.x. The fix is consistent across versions.