note 57760 deleted from language.oop by felipe
| From: | felipe@php.net | Date: | Wed, 23 Apr 2008 11:32:23 +0000 |
| Subject: | note 57760 deleted from language.oop by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138684@lists.php.net to get a copy of this message | ||
Note Submitter: pascal dot poncet at netconsult dot com
----
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