Generally I connect and retrieve data using the standard way (error checking removed for simplicity):
$db = mysql_select_db('dbname', mysql_connect('host','username','passord')); $items = mysql_query('SELECT * FROM $db'); while($item = mysql_fetch_array($items)) { my_function($item[rowname]); }
Where my_function does some useful things witht that particular row.
What is the equivalent code using objects?
Since version 5.1, PHP is shipped with the PDO driver, which gives a class for prepared statements.
see PDO driver at php.net
Note that this way (with prepared statements) will automatically escape all that needs to be and is one of the safest ways to execute mysql queries, as long as you use binbParam or bindValue.
There is also the mysqli extension to do a similar task, but I personally find PDO to be cleaner.
What going this whole way around and using all these steps gives you is possibly a better solution than anything else when it comes to PHP.
You can then use $query->fetchobject to retrieve your data as an object.