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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
14 + 18 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 01:01:28 2024 UTC