|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-07-22 09:28 UTC] uw@php.net
[2017-10-24 04:26 UTC] kalle@php.net
-Status: Open
+Status: Suspended
[2017-10-24 04:26 UTC] kalle@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 04:00:01 2025 UTC |
Description: ------------ On a number of examples on the mysqlnd_ms documentation, this code is shown: <?php /* Load balanced following "myapp" section rules from the plugins config file */ $mysqli = new mysqli("myapp", "username", "password", "database"); if (mysqli_connect_errno()) /* Of course, your error handling is nicer... */ die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); However, there is a problem here - because mysqlnd_ms connections are lazy and will not actually be connected until a statement is executed, the call to mysqli_connect_errno() will return 0. There is no way to check the connection has succeeded unless you executed a statement and check for errno or validate only that $mysqli is actually instantiated as a mysqli object. Test script: --------------- Make sure the credentials below will not actually work on your MySQL instance, if so, die() will not be triggered. <?php /* Load balanced following "myapp" section rules from the plugins config file */ $mysqli = new mysqli("myapp", "username", "password", "database"); if (mysqli_connect_errno()) /* Of course, your error handling is nicer... */ die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error())); ?>