Req #32098 [Opn->Bgs]: MySQLi object connection status function

From: Date: Thu, 06 Jan 2011 14:16:44 +0000
Subject: Req #32098 [Opn->Bgs]: MySQLi object connection status function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157679@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=32098&edit=1

 ID:                 32098
 Updated by:         uw@php.net
 Reported by:        tj at primetimesolutions dot com
 Summary:            MySQLi object connection status function
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            MySQLi related
 Operating System:   All
 PHP Version:        5.0.3
-Assigned To:        
+Assigned To:        mysql
 Block user comment: N
 Private report:     N

 New Comment:

I don't understand. var_dump($no_connected_mysqli_object) gives you.

Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'root'@'localhost' (using password: YES) in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 2

Warning: var_dump(): Property access is not allowed yet in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Property access is not allowed yet in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3

Warning: var_dump(): Couldn't fetch mysqli in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 3
object(mysqli)#1 (17) {
  ["affected_rows"]=>
  NULL
  ["client_info"]=>
  NULL
  ["client_version"]=>
  int(50007)
  ["connect_errno"]=>
  int(1045)
  ["connect_error"]=>
  string(63) "Access denied for user 'root'@'localhost' (using password:
YES)"
  ["errno"]=>
  NULL
  ["error"]=>
  NULL
  ["field_count"]=>
  NULL
  ["host_info"]=>
  NULL
  ["info"]=>
  NULL
  ["insert_id"]=>
  NULL
  ["server_info"]=>
  NULL
  ["server_version"]=>
  NULL
  ["sqlstate"]=>
  NULL
  ["protocol_version"]=>
  NULL
  ["thread_id"]=>
  NULL
  ["warning_count"]=>
  NULL
}


And:

$m = @new mysqli("localhost", "root", "rooti");
var_dump(@$m->connect_error);

ixnutz@linux-fuxh:~/php/php-src/branches/PHP_5_3_cta> sapi/cli/php
foo.php

Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'root'@'localhost' (using password: YES) in
/home/nixnutz/php/php-src/branches/PHP_5_3_cta/foo.php on line 2
string(63) "Access denied for user 'root'@'localhost' (using password:
YES)"


There's your propery. If you suppress warnings you can even access it.


Previous Comments:
------------------------------------------------------------------------
[2005-02-24 23:03:11] tj at primetimesolutions dot com

Description:
------------
It would be helpful and spiffy to have a function or member variable on
MySQLi objects that one could use to determine if the connection was a
success or failure.  According to the documentation, the solution is to
call the mysqli_connect_errno() function after construction of the
object, but doing so sort of eliminates the "object oriented-ness" of
the design, and causes sloppy code (i.e. extra variables required to
store status of different connection successes, etc.).



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



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=32098&edit=1


Thread (2 messages)

« previous php.bugs (#157679) next »