Doc #54572 [Opn->Bgs]: default ini values are not used when constructing new mysqli()

From: Date: Wed, 20 Apr 2011 03:11:11 +0000
Subject: Doc #54572 [Opn->Bgs]: default ini values are not used when constructing new mysqli()
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6263@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54572&edit=1 ID: 54572 Updated by: dtajchreber@php.net Reported by: marcos at generic dot cx Summary: default ini values are not used when constructing new mysqli() -Status: Open +Status: Bogus Type: Documentation Problem Package: MySQLi related Operating System: MacOS PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: You need a $sadmysqli->real_connect(); after creating the object. Mind the note on the page: "Calling the constructor with no parameters is the same as calling mysqli_init()." Add the real_connect() call and you can ini_set the mysqli ini settings as much as your little heart desires and it'll work as expected: [david@oslo:~]$ mysql -u root -p Enter password: mysql> use php; Database changed mysql> select * from test; +--------+-------+------------+ | idtest | fname | lname | +--------+-------+------------+ | 0 | david | tajchreber | +--------+-------+------------+ 1 row in set (0.00 sec) mysql> exit Bye [david@oslo:~]$ cat t.php <?php error_reporting(E_ALL | E_STRICT); ini_set('mysqli.default_host', 'localhost'); ini_set('mysqli.default_socket', '/var/run/mysqld/mysqld.sock'); ini_set('mysqli.default_user', 'root'); ini_set('mysqli.default_pw', 'root'); $m = new MySQLi(); var_dump($m->real_connect()); var_dump($m->ping()); var_dump($m->select_db('php')); var_dump($m->query('select * from test;', MYSQLI_USE_RESULT)->fetch_all()); [david@oslo:~]$ php t.php bool(true) bool(true) bool(true) array(1) { [0]=> array(3) { [0]=> string(1) "0" [1]=> string(5) "david" [2]=> string(10) "tajchreber" } } Previous Comments: ------------------------------------------------------------------------ [2011-04-20 01:21:58] marcos at generic dot cx Description: ------------ --- From manual page: http://www.php.net/mysqli.connect#Description --- The documentation says: mysqli::__construct() ([ string $host = ini_get("mysqli.default_host") [, string $username = ini_get("mysqli.default_user") [, string $passwd = ini_get("mysqli.default_pw") [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] ) this implies that you can set these values via ini_set() and instantiate a new mysqli() with no arguments, but this does not actually work. This is similar to http://bugs.php.net/bug.php?id=38998&edit=2 except that case revolved around passing null to the constructor. The documentation says: "If not provided or NULL, the MySQL server will attempt to authenticate the user against those user records which have no password only. This allows one username to be used with different permissions (depending on if a password as provided or not)." but this is inconsistent with the constructor signature which implies that these values are auto-populated from the ini values. If the ini parameters serve no purpose in an empty constructor invocation, then the documentation signature should be updated to reflect that the mysql.default_* ini values have no effect (or are overridden by the behavior that follows). i.e. the signature should read mysqli::__construct() ([ string $host = "localhost" [, string $username = ini_get("mysqli.default_user") [, string $passwd = "" [, string $dbname = "" [, int $port = ini_get("mysqli.default_port") [, string $socket = ini_get("mysqli.default_socket") ]]]]]] ) which implies a very different behavior. Test script: --------------- ini_set("mysqli.default_host", "localhost"); ini_set("mysqli.default_user", "jack"); ini_set("mysqli.default_pw", "florey"); $sadmysqli = new mysqli(); $happymysqli = new mysqli(ini_get("mysqli.default_host"), ini_get("mysqli.default_user"), ini_get("mysqli.default_pw")); print_r($sadmysqli->host_info); // ERROR: DB::__construct() [<a href='db.--construct'>db.--construct</a>]: Property access is not allowed yet print_r($happymysqli->host_info); // Localhost via UNIX socket Expected result: ---------------- the result for both print_r statements should be equivalent. this makes it seem as if the default ini values for the constructor are not actually being used when calling the constructor Actual result: -------------- see above, namely DB::__construct() [<a href='db.--construct'>db.--construct</a>]: Property access is not allowed yet ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54572&edit=1

« previous php.doc.bugs (#6263) next »