hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

MySQLi error codes different from PHP ones

Open woxxy opened this issue 12 years ago • 4 comments

For mistake I inputted a port higher than 65535 in MySQLi for unit testing. MySQLi extension goes through without noticing an error in HHVM:

$conn = new \MySQLi('127.0.0.1', null, null, null, 93067, null);

var_dump($conn->connect_error);
var_dump($conn->connect_errno);
var_dump(mysqli_connect_error());

Output:

$ hhvm test.php
NULL
int(0)
NULL

$ php test.php
PHP Warning:  mysqli::mysqli(): (HY000/2002): Connection refused in /vagrant/sphinxql/test.php on line 3

Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /vagrant/sphinxql/test.php on line 3
string(18) "Connection refused"
int(2002)
string(18) "Connection refused"

Then I tried with port numbers within the limit and noticed another difference:

$conn = new \MySQLi('127.0.0.1', null, null, null, 1337, null);

var_dump($conn->connect_error);
var_dump($conn->connect_errno);
var_dump(mysqli_connect_error());

Output:

$ hhvm test.php

Warning: mysql_connect(): Can't connect to MySQL server on '127.0.0.1' (111)
string(50) "Can't connect to MySQL server on '127.0.0.1' (111)"
int(2003)
string(50) "Can't connect to MySQL server on '127.0.0.1' (111)"

$ php test.php
PHP Warning:  mysqli::mysqli(): (HY000/2002): Connection refused in /vagrant/sphinxql/test.php on line 3

Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /vagrant/sphinxql/test.php on line 3
string(18) "Connection refused"
int(2002)
string(18) "Connection refused"

HHVM gives error 2003 and PHP error 2002.

Also, HHVM doesn't show the warning like MySQLi does in PHP.

$ hhvm --version
HipHop VM 3.1.0-dev+2014.04.27 (rel)
Compiler: heads/master-0-g991e92dc79342cf6d28738e599f0b769524b29e8
Repo schema: 5f8ba775524b64db3ec5f27a5c4019a3c7f68362

woxxy avatar May 18 '14 11:05 woxxy

From http://dev.mysql.com/doc/refman/5.0/en/error-messages-client.html

Error: 2002 (CR_CONNECTION_ERROR) Message: Can't connect to local MySQL server through socket '%s' (%d) Error: 2003 (CR_CONN_HOST_ERROR) Message: Can't connect to MySQL server on '%s' (%d)

So maybe the error messages depend in the implementation?

SiebelsTim avatar May 27 '14 08:05 SiebelsTim

@woxxy Your first error has been fixed. HHVM now displays the two strings int for a port out of range. Re: the differences in error code, I think this is possibly more a function of the MySQL implementation being used. E.g., we could be calling into a libmysql while PHP 5.x is using mysqlnd, and that could cause discrepancies.

http://dev.mysql.com/downloads/connector/php-mysqlnd/

I am going to mark this a wontfix for now and close the issue. If you or @fredemmott or anyone else disagrees with my reasoning, please re-open and we can discuss.

JoelMarcey avatar Nov 20 '14 05:11 JoelMarcey

PHP can use either libmysql or mysqlnd so if there is a difference between them PHP is equally wrong.

WizKid avatar Nov 20 '14 19:11 WizKid

We don't have consistent error messages with PHP in a lot of places.

paulbiss avatar Nov 20 '14 20:11 paulbiss