Hello Guys How Are you all ? Hope You All Are fine. Recently my laravel Application stopped working. When I Show my Log I found the stack trace of error And It was:
SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from tb_users where (username = 'patel') limit 1)
What Is The Issue ?
Suddenly got
SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from
tb_users
where (username
= 121211) limit 1)
on Laravel.
This issue started after the recent MariaDB update after Updating MariaDB to v10.3.26 (and 10.2.35). This issue is already defined at here: https://jira.mariadb.org/browse/MDEV-24121
What Is Solution For SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL
All Of My Laravel Apps Running on PHP Version 7.2 and this all Project have this Error, But Those Running PHP 7.3 They have not this error so I am Just Updated my all project to PHP version 7.3.
Question : How to solve SQLSTATE[HY000]: General Error: 1835 Malformed communication packet on Laravel ?
Answer : All Of My Laravel Apps Running on PHP Version 7.2 and this all Project have this Error, But Those Running PHP 7.3 They have not this error so I am Just Updated my all project to PHP version 7.3
Here Is All Possible Solution For SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL.
1. Upgrade your PHP to 7.3: It appears these errors are shown on sites using php < 7.3. So upgrading your site’s PHP to version 7.3 or 7.4 should resolve the issue.
2. Downgrade MariaDB: This is a temporary fix since downgrading MariaDB will set it back to the previous state.
3. Add ‘options’ => [PDO::ATTR_EMULATE_PREPARES => true] to Database Config(config/database.php):
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', '**'),
'username' => env('DB_USERNAME', '**'),
'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]**
],
This has been suggested in some answers which might solve 1 issue but open up a lot of other issues.
4. Wait for MariaDB Update: The next update should address this issue.
5. Change PHP Version : 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).
Summery
So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below on your suggestion.