php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67573 Misleading Doc Samples
Submitted: 2014-07-04 15:05 UTC Modified: 2017-10-24 04:26 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: accounts at dotmanila dot com Assigned:
Status: Suspended Package: mysqlnd_ms (PECL)
PHP Version: 5.4.30 OS: CentOS 6.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: accounts at dotmanila dot com
New email:
PHP Version: OS:

 

 [2014-07-04 15:05 UTC] accounts at dotmanila dot com
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()));
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-22 09:28 UTC] uw@php.net
Good find; however, I am not sure from top of my head whether connect_errno will be 0 all the time. I bet we set it, e.g when parsing the ini file fails or an invalid host is given, hence, it makes sense to check.
 [2017-10-24 04:26 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-10-24 04:26 UTC] kalle@php.net
I'm gonna suspend this report as the mysqlnd_ms had not a release since 2013 or active commit activity since then, if activity comes back to this package, it should be re-opened
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC