Doc #80529 [Com]: $mysqli->connect_errno may not work

From: Date: Thu, 17 Dec 2020 23:58:06 +0000
Subject: Doc #80529 [Com]: $mysqli->connect_errno may not work
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18282@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80529&edit=1 ID: 80529 Comment by: a at b dot c dot de Reported by: bugs dot php dot net at latter dot org Summary: $mysqli->connect_errno may not work Status: Not a bug Type: Documentation Problem Package: MySQLi related PHP Version: Irrelevant Assigned To: cmb Block user comment: N Private report: N New Comment: This should probably be reclassified as a Doc bug, because the original code is lifted verbatim from Example 1 of mysql_connect_errno. Previous Comments: ------------------------------------------------------------------------ [2020-12-17 19:42:12] requinix@php.net try { $mysqli = new mysqli('localhost', 'fake_user', 'my_password', 'my_db'); } catch (\Throwable $t) { echo $mysqli->connect_errno; } It's not a scope problem. It's a "if there was an exception thrown before/during the 'new mysqli' then the $mysqli variable will not be assigned" problem. ------------------------------------------------------------------------ [2020-12-17 19:20:37] bugs dot php dot net at latter dot org Definitely using the object. But we are trying to use the mysqli object inside an exception block. Seems to be some scope issues. ------------------------------------------------------------------------ [2020-12-17 18:39:53] cmb@php.net Apparently, you are confusing new mysqli() with mysqli_connect(). ------------------------------------------------------------------------ [2020-12-17 18:18:21] bugs dot php dot net at latter dot org Description: ------------ --- From manual page: https://php.net/mysqli.construct --- This example code is given (as below) but if mysqli() returns false (as it will if for example the specified database does not exist) then $mysqli->connect_errno will generate a PHP warning of "Trying to get property 'connect_errno' of non-object". $mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db'); if ($mysqli->connect_errno) { die('Connect Error: ' . $mysqli->connect_errno); } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80529&edit=1

« previous php.doc.bugs (#18282) next »