PHP 8.2 MySQLi "The number of variables must match the number of parameters in the prepared statement"

0

Hi,

On our new PHP 8.2 Elastic Beanstalk environment (running platform v4.1.0, PHP 8.2.15) we're getting some intermittent MySQLi "The number of variables must match the number of parameters in the prepared statement" errors.

Note that this fails at the call to "execute()" - not at the call to bind_param()!

This is happening on statements that have never errored in the PHP 7.4 environment, and even with the same parameter values only error in this way periodically (for example, one particular statement was failing 50% of the time, another has failed once in hundreds of calls).

For example (again please note it fails on the execute(), not on the bind_param():

        $stmt1 = $dbConn->prepare("DELETE FROM `some_table` 
        	WHERE ( `active` = 'N' AND `date` < ? )
        	OR ( `date` < ? )
        	LIMIT ?");
        $stmt1->bind_param('ssi', $inactiveThreshold, $thresholdDate, $deleteLimit);
        $stmt1->execute(); // fails here.
        $stmt1->close();

Has anyone else been experiencing this issue?

Thanks, Iain

Iainb
asked a month ago122 views
1 Answer
0

Check that the PHP MySQLi extension is installed and enabled. On Elastic Beanstalk, extensions are configured through .ebextensions files.

Verify the number of parameters matches in your prepared statements. Double check your SQL and parameter binding.

Increase error reporting in your PHP configuration to get more details on the errors. You can set display_errors to On and adjust error_reporting levels.

Review your application logs and CloudWatch metrics for any spikes in memory or CPU usage around the error occurrences. Insufficient resources could cause intermittent issues.

Try simplifying the statement and parameters to isolate whether it's related to complexity. Rule out any potential quote or special character issues.

As a test, hardcode the parameter values in the statement instead of binding to check if the error still happens.

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions