note 103521 added to mysqli.connect
| From: | boukeversteegh at gmail dot com | Date: | Mon, 18 Apr 2011 13:19:37 +0000 |
| Subject: | note 103521 added to mysqli.connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178937@lists.php.net to get a copy of this message | ||
(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;
?>
----
Server IP: 69.147.83.197
Probable Submitter: 192.87.139.139
----
Manual Page -- http://www.php.net/manual/en/mysqli.connect.php
Edit -- https://master.php.net/note/edit/103521
Del: integrated -- https://master.php.net/note/delete/103521/integrated
Del: useless -- https://master.php.net/note/delete/103521/useless
Del: bad code -- https://master.php.net/note/delete/103521/bad+code
Del: spam -- https://master.php.net/note/delete/103521/spam
Del: non-english -- https://master.php.net/note/delete/103521/non-english
Del: in docs -- https://master.php.net/note/delete/103521/in+docs
Del: other reasons-- https://master.php.net/note/delete/103521
Reject -- https://master.php.net/note/reject/103521
Search -- https://master.php.net/manage/user-notes.php