
Very easily...
I’ve tried to get all user ids into an array using xpdo queries but everything I try fail. Tried to follow the examples but no luck. Good side is that I’ve read the rtfm many times now.
Problem is that I can’t get the whole object for 28000 users as it gives memory errors and takes for ever, so getCollection isn’t an option.
Tried to search (I think I read about it before but can’t find it). Everything leads to the getValue snippet which doesn’t work as it retrieves the whole object.
So, how can I in a Revo style get all values for a single column in a fast and low memory query?
Thanks!
<?php
// build a query using the API
$query = $modx->newQuery('modUser');
$query->select($modx->getSelectColumns('modUser', '', '', array('id')));
$query->sortby($modx->escape('id'), 'ASC');
// now prepare a PDOStatement and execute it
$userIds = array();
if ($query->prepare() && $query->stmt->execute()) {
// xPDOQuery (and it's parent class, xPDOCriteria) wrap a PDOStatement
// and you can use it like any PDOStatement, e.g. PDO::FETCH_COLUMN
$userIds = $query->stmt->fetchAll(PDO::FETCH_COLUMN);
} else {
// echo an error to the output in HTML format
$modx->log(modX::LOG_LEVEL_ERROR, "Error executing query:\n" . $query->toSQL(), 'HTML');
}
?>
