PHP try/catch and fatal error

前端 未结 6 1842
庸人自扰
庸人自扰 2020-12-10 01:01

I\'m using the following script to use a database using PHP:

try{
    $db = new PDO(\'mysql:host=\'.$host.\';port=\'.$port.\';dbname=\'.$db, $user, $pass, $o         


        
6条回答
  •  自闭症患者
    2020-12-10 01:47

    Try adding the following if statement :

    if ($db) {
        $query = $db->prepare("INSERT INTO users (...) VALUES (...);");
        $query->execute(....);
    }
    else die('Connection lost');
    

提交回复
热议问题