Code 10x More Efficiently Using Data Access Objects: Part 1 - The Old Way (Page 2 of 6 )
As mentioned earlier, PHP provides great built-in functions that allow the developer to connect to a database and retrieve some data. (If you are an experienced PHP programmer and do not feel like getting bored with the "same old", skip ahead to the section titled "Database DAO to the Rescue").
In what ways do we usually need the data returned from a database, and in what format do we like to have the data returned? In my years of development I have realized that in overwhelming majority of cases I need to have my data returned in three ways: as a single value, as one record, and as many records.
Let's see how we would go about getting a value, a record, and a recordset returned from the database the "old way." PHP is most frequently coupled with the MySQL database software, so let's use it for our example. I have a contact database with a "Contacts" table full of, you guessed it, contacts. The database is accessible on the "localhost", the user is "user", the password is "password", and the table structure looks something like this: