New Mysqli Object - Null
I am trying to create a connection to a MySQL database using Mysqli in PHP. When I execute the following code on a separate page:
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); $link = new mysqli('localhost', 'myuser', 'mypass', 'dbname'); var_dump($link);
All I get is an empty Mysqli object, where all properties are null. No error or anything is displayed.
I also do not see entries in the Apache or MySQL logs. I seemed to be lost on this.
I also had this problem, and I went crazy trying to debug it. It turns out that sometimes for some reason the mysqli object is not populated, but directly accesses its properties, which still executes its own code. Therefore, in spite of the fact that var_dump of the whole mysqli object shows null properties, they exist if you access them individually. If errorno is false, you may have completed the correct query with an empty result set that you did not expect. Hope this helps.
$mysqli = mysqli_connect('localhost', 'root', '', 'test', 3306); var_dump($mysqli); var_dump($mysqli->client_info); var_dump($mysqli->client_version); var_dump($mysqli->info);
and conclusion:
object(mysqli)[1] public 'affected_rows' => null public 'client_info' => null public 'client_version' => null public 'connect_errno' => null public 'connect_error' => null public 'errno' => null public 'error' => null public 'field_count' => null public 'host_info' => null public 'info' => null public 'insert_id' => null public 'server_info' => null public 'server_version' => null public 'stat' => null public 'sqlstate' => null public 'protocol_version' => null public 'thread_id' => null public 'warning_count' => null string 'mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $' (length=50) int 50008 null int 0 string 'localhost via TCP/IP' (length=20) string '5.5.20-log' (length=10) int 50520
I know this is a bit outdated, but for those who still have this as a recurring problem, the comment from user3158900 on the danperron post has a solution. I am rewriting here to make it more visible. In addition, an example code is provided:
global $mysqli; //assuming you've already created your $mysqli object $mysqli->query("INSERT INTO users SET username='jim' and password='somehash'"); var_dump( $mysqli ); //prints the full object but all the values are null //the following code prints the full object with appropriate values such as //insert_id, affected_rows, etc //view http://pastebin.com/Mgd2CZsM for an example of this output echo "<pre>" . print_r( $mysqli, true ). "</pre>";