|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-02-22 04:45 UTC] frankpw at fw2s dot com
Description:
------------
In my class I'm opening a connection with mysqli_connect(). mysqli_connect_error() returns description of any error except one. If one parameter is of wrong type (i.e port as string rather than numeric).
Reproduce code:
---------------
public function OpenConnection($host, $user, $pass, $name = null, $port = null, $sock = null, $chrs = null)
{
$this->mysqli = @mysqli_connect($host, $user, $pass, $name, $port, $sock);
if (empty($this->mysqli)) die ("Execution stopped! " . mysqli_connect_error() . "<br />\n");
if (!empty($chrs)) $this->DefaultCharacterSet($chrs);
}
Expected result:
----------------
"Execution stopped! mysqli_connect expects parameter 5 to be long, string given"
Actual result:
--------------
"Execution stopped!"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 10:00:01 2025 UTC |
Additional info: Server info: 5.0.27-community-max-nt Client info: 5.0.22 That's as close to match server and client versions as it gets. I've downloaded php_mysql.dll and php_mysqli.dll for server version 5.0.27 directly from MySQL. Please try the code below: <?php $mysqli = @mysqli_connect("localhost","root","pass",null,"abcd"); if (empty($mysqli)) die ("Connection attempt failed! " . mysqli_connect_error() . "<br />\n"); echo "Connected!<br />\n"; echo "Host info: " . mysqli_get_host_info($mysqli) . "<br />\n"; echo "Client info: " . mysqli_get_client_info() . "<br />\n"; echo "Server info: " . mysqli_get_server_info($mysqli) . "<br />\n"; echo "Protocol version: " . mysqli_get_proto_info($mysqli) . "<br />\n"; ?> For test purposes make sure that first four parameters are correct and use fifth as is. Repeat the test with "@" removed from the call to mysqli_connect(). You'll see that warning is being displayed but mysqli_connect_error() is empty and mysqli_connect_errno() == 0.That is not a point. Even the manual shows how connection errors should be handled: /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } This check fails in this particular case because mysqli_connect_error() is empty and mysqli_connect_errno is 0. Are you insisting that this is not connection error and that it shoud be handled differently?