php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32098 MySQLi object connection status function
Submitted: 2005-02-24 23:03 UTC Modified: 2011-01-06 15:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tj at primetimesolutions dot com Assigned: mysql (profile)
Status: Not a bug Package: MySQLi related
PHP Version: 5.0.3 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tj at primetimesolutions dot com
New email:
PHP Version: OS:

 

 [2005-02-24 23:03 UTC] 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.).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:47 UTC] jani@php.net
-Package: Feature/Change Request +Package: MySQLi related
 [2011-01-06 15:16 UTC] uw@php.net
-Status: Open +Status: Bogus -Assigned To: +Assigned To: mysql
 [2011-01-06 15:16 UTC] uw@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC