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
已提問 2 個月前檢視次數 138 次
1 個回答
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
專家
已回答 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南