public function getAllAddOns()
{
return $this->fetchAllKeyed('
SELECT *
FROM xf_addon
ORDER BY title
', 'addon_id');
}
Correct, this has been established. Can you just do fetchAllKeyed() or does the code require you do $this->fetchAllKeyed()?fetchAllKeyed is a method of the Model Class AND NOT from ZEND DB
so you have to call it direct![]()
Odd, didn't know that. As far as PHP goes anyways. Learn something new everyday, eh?Methods can only be run with $this-> like in this case (or self:: or parent:: or classname:: for static methods)![]()
Theoretically doesn't the server just take the class out of memory(actually the whole php script for that matter) as soon as it's done completely executing the page?No, you don't need to worry about cleanup like that in the vast majority of cases. It's micro-optimisation anyway, and largely pointless.
$this->_getDb()->fetchAll('
SELECT *
FROM xyz
WHERE abc = 1');
$this->_getDb()->fetchAll('
SELECT *
FROM xyz
WHERE abc = ?', 1);
It seems a bit weird to me that you can't query the number of rows faster. I don't see how it could be good for performance to have to query every row of a table and then use count() on it. Come to think of it COUNT(*) would be better then what you have said.
So instead of
$numRows = count($db->fetchAll("SELECT * FROM `xf_user`"));
Do...
list($numRows) = $db->fetchRow("SELECT COUNT(*) FROM `xf_user`");
Note: I am fairly tired so may have messed something up there.
$numRows = count($db->fetchAll("SELECT * FROM `xf_user`"));
$things = $db->fetchAll('SELECT * FROM xf_thing');
$numThings = count($things);
$numThings = $db->fetchOne('SELECT COUNT(*) FROM xf_thing');
Yeah I was really hoping they weren't right in the OP. And I was close to getting it right, guess I should actually look at the database layer onedayShould never appear, it's a huge waste of resources. The only time PHP's count() should be used in this way is to count the number of records from a data set that has been fetched already for its own purpose:PHP:$numRows = count($db->fetchAll("SELECT * FROM `xf_user`"));
If you just need to count the number of things in the database, use SQL's COUNT(*).PHP:$things = $db->fetchAll('SELECT * FROM xf_thing'); $numThings = count($things);
PHP:$numThings = $db->fetchOne('SELECT COUNT(*) FROM xf_thing');
We use essential cookies to make this site work, and optional cookies to enhance your experience.