note 103521 deleted from mysqli.construct by philip
| From: | philip@php.net | Date: | Wed, 02 Sep 2015 21:19:47 +0000 |
| Subject: | note 103521 deleted from mysqli.construct by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203584@lists.php.net to get a copy of this message | ||
Note Submitter: boukeversteegh at gmail dot com
----
(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;
?>