Prev | Current Page 139 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

There is no right answer. In my current job, we have sold to
customers who will only use SQL Server and will not countenance the use of MySQL or PostgreSQL, so we
have found database abstraction layers very useful for making sales.
The Zend Framework??™s interface to the database is via an abstraction layer. The standardized interface to
the database that this gives ensures that the higher level components will work with any database. It also means
that the support for a given database is encapsulated at a single point and so supporting new database engines
is easier. We will now look at using the Zend Framework??™s Zend_Db_Adapter to connect to a database and
then interact with the data within it.
5.1.1 Creating an Zend_Db_Adapater
The heart of the database abstraction components within the Zend Framework is Zend_Db_Adapter_Abstract.
Each supported database engine has a specific adapter class that inherits from this class. For example, DB2??™s
adapter is named Zend_Db_Adapter_Db2. The PDO library is also used to for some adapters, such as
Zend_Db_Adapter_Pdo_Pgsql for PostgreSQL.
The Factory design pattern is used to create a database adapter using the Zend_Db::factory() function a shown
in listing 5.1:
Listing 5.1: Creating a Zend_Db_Adapter instance using the factory function Zend_Db::factory()
$params = array ('host' => 'localhost', |#1
Licensed to Menshu You

Pages:
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
dobrzybukmacherzy.info ogrzewanie lubuskie House Extension London opony michelin botox Kraków