简体   繁体   中英

PDO general error: 2006 mysql server has gone away

I am using linux and tried to create some tables using php 7.2 but it will give an error as follows, when I execute command. Can anyone help me to fix this problem?

[PDOException] SQLSTATE[HY000] [2006] MySQL server has gone away
[ErrorException] PDO::__construct(): MySQL server has gone away

class Database extends PDO{
    function __construct(){
        $options = array(
            PDO::ATTR_PERSISTENT => true,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        );
        try{
            parent::__construct(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8',DB_USER,DB_PASS, $options);
        }catch (PDOException $e) {
            echo "Got PDOException\n";
            var_dump($this);
        }

    }
}

I can not set the instructions for this page to the class I have https://dev.mysql.com/doc/refman/8.0/en/gone-away.html

$ db-> exec('SET session wait_timeout = 60');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM