. Advertisement .
..3..
. Advertisement .
..4..
The error: “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
When Do You Get The Error: “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL”?
Your Laravel application recently stopped working. Then, when opening your log, you discovered the stack trace of the error, which was as follows:
SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from tb_users where (username = 'patel') limit 1)
This problem first appeared after MariaDB was updated to version 10.3.26. (and 10.2.35). This problem has already been defined here: Recent MariaDB update appears to have introduced a DB connection issue for PHP < 7.3 (or anything using PDO).
How To Solve The Error: “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL”?
Approach 1: Downgrade MariaDB
This is only a temporary solution for the error “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL” because downgrading MariaDB would return it to its prior state.
CON: Downgrading MariaDB is not something that can be done with a single click from cpanel. A network engineer might be needed to perform the downgrade for you. The MariaDB packages may then need to be yum-locked in order to prevent updates until they have been patched.
Approach 2: Include ‘options’ => [PDO::ATTR_EMULATE_PREPARES => true] in Database Config(config/database.php)
Another way for the error “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL” is including ‘options’ => [PDO::ATTR_EMULATE_PREPARES => true] in Database Config(config/database.php). Look at the following example to understand more about this method:
'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 proposed in several answers, which may solve one problem but create a slew of new ones.
Approach 3: Update your PHP to 7.3
These issues appear to be displayed on sites that use PHP 7.3. As a result, updating your site’s PHP to version 7.3 or 7.4 will fix the problem.
Approach 4: Wait for the next MariaDB update
This issue should be resolved in the next version.
CONS: The time it will take for an update to fix this problem for older versions of PHP is unknown. Some applications might not be able to wait that long; it could possibly be days.
Overall, these are the only choices I can think of right now. Just hoping a fix will be available shortly.
In the short term: Given that my application needs a lot of work to be ready for PHP 7.3, upgrading MariaDB appears to be the only quick (kind of) fix for me. The error has vanished when I locked MariaDB and reduced it to version 10.2.34.
In the long term: To ensure that MariaDB’s more recent versions do not complain, it is preferable to gradually prepare your application for PHP 7.3 and upgrade to it.
Approach 5: Alter PHP Version
This problem occurred in all of the Laravel apps running PHP 7.2, but not in those using PHP 7.3. As a result, you should upgrade PHP to version 7.3, and the issue will be fixed.
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “SQLSTATE[HY000]: General error: 1835 Malformed communication packet on LARAVEL” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Read more
Leave a comment