Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL

Suddenly got

SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from tb_users where (username = 121211) limit 1)

on Laravel.

I already checked this: MySQL: ERROR 2027 (HY000): Malformed packet, but it seems a different case.

  1. I've successfully logged in to MySQL after previously login using SSH (using: mysql -u -p).
  2. I've successfully logged in to MySQL directly from a remote PC (using: mysql -h [IP] -u -p).

But my Laravel got the error I mentioned before. Any experience in this?

like image 471
wbhuana Avatar asked Nov 04 '20 09:11

wbhuana


2 Answers

All my Laravel apps running PHP 7.2 had this error but those running on PHP 7.3 did not. So I changed the PHP version to 7.3 and the problem was fixed. (Running Laravel 7)

like image 200
felixmensah6 Avatar answered Sep 17 '22 05:09

felixmensah6


Found the solution. Don't know if it's permanent or temporary:

'mysql' => [             'driver' => 'mysql',             'host' => env('DB_HOST', '127.0.0.1'),             'port' => env('DB_PORT', '3306'),             'database' => env('DB_DATABASE', 'forge'),             'username' => env('DB_USERNAME', 'forge'),             'password' => env('DB_PASSWORD', ''),             'unix_socket' => env('DB_SOCKET', ''),             'charset' => 'utf8mb4',             'collation' => 'utf8mb4_unicode_ci',             'prefix' => '',             'strict' => false,             'engine' => null,             **'options'   => [PDO::ATTR_EMULATE_PREPARES => true]**         ], 

make sure that

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

exist on mysql connection.

like image 44
wbhuana Avatar answered Sep 20 '22 05:09

wbhuana