note 83419 deleted from mysqli.connect by danielc

From: Date: Thu, 12 Mar 2009 19:51:12 +0000
Subject: note 83419 deleted from mysqli.connect by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151799@lists.php.net to get a copy of this message
Note Submitter: lgz2648 at 163 dot com Reason: 0 ---- The Object oriented style <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); ?> always returns a object which represents connection to a MYSQL,also connection faild , so the code below won't throw a Exception when connection faild: <?php try { $db = new mysqli('localhost', 'userName', 'passWord', 'dbName'); if(!$db){ throw new Exception('connect databases faild!'); } } catch (Exception $e){ echo $e->getMessage(); } ?> you must check connection with mysqli_connect_errno() <?php try { $db = new mysqli('localhost', 'userName', 'passWord', 'dbName'); if(mysqli_connect_errno()){ throw new Exception('connect databases faild!'); } } catch (Exception $e){ echo $e->getMessage(); } ?>

« previous php.notes (#151799) next »