Take a look at How to convert sql query to magento in order to fetch dataHow to convert sql query to magento in order to fetch data
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$readresult = $read->query("SELECT id FROM customers_old");
while ($row = $readresult->fetch() ) {
$Ids[] = $row['id'];
}
See Conquer the 5 Most Common Magento Coding Issues to Optimize Your Site for Performance