Code 10x More Efficiently Using Data Access Objects: Part 1 - Conclusion
(Page 6 of 6 )
The advantages of using a database data access object over conventional database access are rather obvious. Of course, there are many cases where the conventional database access may be necessary. For example, in order to retrieve field names and their associated data types from a particular table, we would connect to a database in the conventional way and use the "mysql_fetch_field()" PHP function. The point is that about 95% of the time (if not more) we are simply retrieving data from a database and in that case DAO is the tool of choice.
Although at the beginning of this article I made a claim that the DAO is not an abstraction layer, it is not entirely true. As a matter of fact, I have to admit that our implementation of the DAO can be perceived as a database abstraction layer to a certain degree. The "Core Classes" collection also includes a "MsSqlAdapter," which acts as a DAO for access to Microsoft's SQL Server. Since the exposed class interface is exactly the same as the interface in "MySQL Adapter," scripts that utilize the MySQL DAO can be converted to work with MSSQL server simply by modifying the include statement to include the "mssqladapter.phpclass."
I realize that in addition to retrieving data from a database, many of the scripts need to store data in a database as well. Updating and inserting records in a database is often even more of a hassle than retrieving it, and don't worry, database DAO can do that as well. If you are interested to learn about the remaining functionality of the MySQL data access object, come back and look for the part "deux" of this article.
Support Material
Download the MySQLAdapter DAO Class from http://eof.nlcnet.net/core/MySQLAdapter.zip. The MySQL Adapter is covered under the LGPL license.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |