note 57758 added to function.get-object-vars
| From: | pascal dot poncet at netconsult dot com | Date: | Thu, 13 Oct 2005 14:20:32 +0000 |
| Subject: | note 57758 added to function.get-object-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96959@lists.php.net to get a copy of this message | ||
Subject: using "sql_calc_found_rows" in a MySQL query while exploiting result in a PHP db
class object.
Hello,
There is a nice function in MySQL that allows to know how many records would have been returned if
no "where" clause were set : SQL_CALC_FOUND_ROWS.
If you have create a db object to collect the returned lines, you will be a little perplex when
trying to call the result of this function.
Why ?
Simply because the returned field's name is "found_rows()" and obviously it's
not possible to call something like :
<?php $result->found_rows() ?>
...as it will try to acces a method, not a property !
Then, the only way to get the right result seems to be the use of a class function, like :
<?php
$db->query("select found_rows()");
$count=current(get_object_vars(current($db->result)));
?>
Of course, if somebody found an other way to solve it, like a special syntax (see the one used with
curled arrays in a string), I'm really open to discuss.
Good luck,
Pascal
----
Manual Page -- http://www.php.net/manual/en/function.get-object-vars.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57758
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57758&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57758&report=yes
Search -- http://master.php.net/manage/user-notes.php