MySQL server has gone away Error in CakePHP

1.3k Views Asked by At

I'm working on CakePHP 3.2

My application was working fine earlier but from last few days giving error as

Error: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

SQL Query

SELECT Categories.id AS Categories__id, Categories.title AS Categories__title, Categories.description AS Categories__description, Categories.icon AS Categories__icon, Categories.c_status AS Categories__c_status, Categories.created AS Categories__created, Categories.modified AS Categories__modified FROM categories Categories WHERE Categories.c_status = 1

and a suggestion

 If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.

I tried with enabling identifier in app.php then also same error.

Source code for generated query

$menu_categories = $this->Categories->find('all', [
    'conditions' => [
      'Categories.c_status' => 1,
    ],
    'contain' => [
      'Subcategories.ProductTypes' => [
        'conditions' => [
          'ProductTypes.status' => 1,
        ],
      ],
      'CategoryBanners' => [
        'conditions' => [
          'CategoryBanners.status' => 1,
        ],
      ],
    ],
]);
$this->set('menu_categories', $menu_categories);

What could be the cause for the error ?

1

There are 1 best solutions below

0
Noahone On

I had this error, and it turned out to be an issue with the "max_allowed_packet" setting for the database. I increased mine from the default up to 16MB, and it resolved my issue. Something to check on and experiment with if you or anybody else is having this error.