(php 5.3.3)
If $port is a string, such as "3306", mysqli::query() will not work, even though mysqli_connect_errno() reports no error (value 0)!
<?php
$mysqli = new mysqli("localhost", "user","password","database", "3306"); //port is a string!
$mysqli->query("SELECT 1;")->fetch_assoc();
// Fatal error: Call to a member function fetch_assoc() on a non-object
?>
This is particularly strange, since mysqli::query() should return a result object, or a boolean.
So, be careful when you read your port from a string or config file. Cast it to int first:
<?php
$port = (int)$port;
?>