ID: 45940
Comment by: ws at develtheory dot com
Reported By: talmage dot news at gmail dot com
Status: Assigned
Bug Type: MySQLi related
Operating System: Centos 5
PHP Version: 5.2.6
Assigned To: mysql
New Comment:
Was able to reproduce the error in the same method on php 5.2.8, both
with purposeful incorrect passwords and nonexistent host/port combos.
the object is created, connect_error returns NULL on var_dump, error
log dumps:
"Dec 25 15:12:18 dev01 httpd: PHP Warning: dbo::__construct() [<a
href='dbo.--construct'>dbo.--construct</a>]: Couldn't fetch mysqli in
/nfs/beta/www/classes/dbo-new.inc.php on line 88"
Previous Comments:
------------------------------------------------------------------------
[2008-12-01 13:39:16] dannyrjohnston at msn dot com
Forget my previous comment. I found some code between the new mysqli
statement in the example I was using which was setting the $dbObj to
false if mysql_connect_error was returning a value.
------------------------------------------------------------------------
[2008-12-01 13:17:14] dannyrjohnston at msn dot com
I have duplicated this issue.
According to the manual mysqli::__construct should always return a
object, but the function is returning a false value on error.
I have tried three different possible error conditions and have the
following results:
Bad user/password combo: mysqli_connect_error() returns "Access
denied for user 'xxx'@'xxx' (using password: YES)", return value is
false.
User does not have access to the db selected:
mysqli_connect_error()returns "Access denied for user 'xxx'@'xxx' to
database 'xxx'", return value is false.
Bad port number: mysqli_connect_error() returns "Can't connect to
MySQL server on 'localhost' (10061)", return value is false.
I have not checked any other cases such as bad socked name, but in each
of the above conditions I received a false value not an object.
test code:
<?php
$dbObj = new mysqli( "localhost", "user", "pass", "db", 3306);
echo "dbObj=";
var_dump($dbObj);
?>
error result:
dbObj=bool(false)
sucess result:
dbObj==object(mysqli)#1 (0) {
}
------------------------------------------------------------------------
[2008-11-29 00:22:45] valentin71 at gmail dot com
Not quite sure that mudroeb is right.
According to manual the right call format must be following:
mysqli mysqli_connect ( [string host [, string username [, string
passwd [, string dbname [, int port [, string socket]]]]]] )
However
conn=new mysqli('localhost','user','password','my_db',3306);
works as expected.
------------------------------------------------------------------------
[2008-11-29 00:08:06] mudroeb at gmail dot com
Get the same problem but make investigation:
$mysqli = new mysqli("localhost:3307", "my_user", "my_password",
"world");
-> got error
$mysqli = new mysqli("127.0.0.1:3307", "my_user", "my_password",
"world");
-> got error
BUT!:
$mysqli = new mysqli("127.0.0.1:3306", "my_user", "my_password",
"world");
-> change server port to default (3306).
$mysqli = new mysqli("localhost", "my_user", "my_password",
"world");
-> all works correct.
Seems that variable not parsed for $HOST_NAME and $PORT_NUMBER and
function try to connect using incorrect (not parsed) string.
------------------------------------------------------------------------
[2008-08-29 11:51:21] [email protected]
I can reproduce that, assigning to mysql folks.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/45940
--
Edit this bug report at http://bugs.php.net/?id=45940&edit=1