note 109383 added to mysqli-result.fetch-object
| From: | jorortega at gmail dot com | Date: | Thu, 12 Jul 2012 19:05:02 +0000 |
| Subject: | note 109383 added to mysqli-result.fetch-object | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-189111@lists.php.net to get a copy of this message | ||
Be aware that, since the class fields get values assigned to them BEFORE the constructor is called,
the...
if ($result = $mysqli->query($query)) {
...statement in some cases has not sense. At all.
Using some example:
$query = "SELECT * FROM City WHERE Country='some country'";
If 'some country' doesn't exist, $query won't be FALSE like with the good old
days, but will be an object with some predefined fields. Thus, in this case, the if statement is
useles, as it will always be TRUE.
In this case, is best to check the object property "num_rows" :
if ($result->num_rows != 0) ...
because if the query fails, num_rows will be asigned the number 0 (integer), and thus, you will know
the query failed.
----
Server IP: 200.29.231.32
Probable Submitter: 200.111.89.146
----
Manual Page -- http://www.php.net/manual/en/mysqli-result.fetch-object.php
Edit -- https://master.php.net/note/edit/109383
Del: integrated -- https://master.php.net/note/delete/109383/integrated
Del: useless -- https://master.php.net/note/delete/109383/useless
Del: bad code -- https://master.php.net/note/delete/109383/bad+code
Del: spam -- https://master.php.net/note/delete/109383/spam
Del: non-english -- https://master.php.net/note/delete/109383/non-english
Del: in docs -- https://master.php.net/note/delete/109383/in+docs
Del: other reasons-- https://master.php.net/note/delete/109383
Reject -- https://master.php.net/note/reject/109383
Search -- https://master.php.net/manage/user-notes.php