note 57759 added to ref.classobj

From: Date: Thu, 13 Oct 2005 14:21:48 +0000
Subject: note 57759 added to ref.classobj
Groups: php.notes 
Request: Send a blank email to php-notes+get-96960@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/ref.classobj.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57759 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57759&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57759&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96960) next »