I need the values of one columns before fetching the query. Something like this:
// mytable +----+-------+ | id | codes | +----+-------+ | 1 | 102 | | 2 | 64 | | 3 | 563 | | 4 | 79 | +----+-------+ My query:
$db = new PDO("mysql:host=localhost;dbname=mydb", "root", ""); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sth = $db->prepare("SELECT * FROM mytable"); $sth->execute(); /* I need to those numbers in the codes-column as an array in here */ while ($results = $sth->fetch()) { var_dump($results); } Well, how can I access this array [0]=>102, [1]=>64, [2]=>563, [3]=>79 before that while() in the above code?
Note: Preferably without the use of fetchAll();
fetchAll, or a second loop based onfetch.whilebyforeachwith that array ar$resultsfetchAll()consumes a lot of memory.. So I'm worry to use it.