ID:               45940
 Comment by:       dannyrjohnston at msn 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:

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) {
}


Previous Comments:
------------------------------------------------------------------------

[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.

------------------------------------------------------------------------

[2008-08-29 03:59:12] talmage dot news at gmail dot com

Upgrading to snap did not fix.


[EMAIL PROTECTED] src]# /usr/local/php/bin/php -v
PHP 5.2.7-dev (cli) (built: Aug 28 2008 20:54:37) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
[EMAIL PROTECTED] src]# /usr/local/php/bin/php -q test.php

Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host
'127.0.0.1:3307' (3) in /srv/php/projects/test/src/test.php on line 4

Warning: main(): Couldn't fetch mysqli in
/srv/php/projects/test/src/test.php on line 7

Warning: main(): Couldn't fetch mysqli in
/srv/php/projects/test/src/test.php on line 12
Host information: 

Warning: mysqli::close(): Couldn't fetch mysqli in
/srv/php/projects/test/src/test.php on line 15
[EMAIL PROTECTED] src]#

------------------------------------------------------------------------

[2008-08-28 21:13:13] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

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

Reply via email to