How to Get Rid of MySQL Error 'Prepared Statement Needs to Be Re-Prepared'

How to get rid of MySQL error 'Prepared statement needs to be re-prepared'

This is a possibility: MySQL bug #42041

They suggest upping the value of table_definition_cache.

You can read about statement caching in the MySQL docs.

Laravel: General error: 1615 Prepared statement needs to be re-prepared

It seems to work adding

'options'   => [
\PDO::ATTR_EMULATE_PREPARES => true
]

Inside projectName/config/database.php file in DB configuration. It will be like this:

'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'options' => [
\PDO::ATTR_EMULATE_PREPARES => true
]
],

Laravel 5.1. Hope it will help!

Edit:
I'm currently on Laravel 8 and this solution is still working.

How to SELECT from a view in SQL? (General error: 1615 Prepared statement needs to be re-prepared)

The solution in this instance was as follows:

Emulation of prepared statements needs to be enabled.

In the connection file, the following line

PDO::ATTR_EMULATE_PREPARES   => false,

needs to be changed like so:

PDO::ATTR_EMULATE_PREPARES   => true,

In other instances it appears the solution may be to increase the table_definitition_cache



Related Topics



Leave a reply



Submit