Prev | Current Page 61 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

In most cases, the model is linked in
some way to a database which will hold data to be manipulated and displayed by the application.
Database abstraction with Zend_Db
Zend_Db is the Zend Framework??™s database abstraction library which provides a suite of functions to insulate
your code from the underlying database engine. This is most useful for those cases when you need to scale
your application from using, say SQLite to MySQL or Oracle. Zend_Db uses the factory design pattern to
provide the correct database-specific class based on the parameters passed into the factory() function. For
example, to create a Zend_Db object for MySQL you would use:
$params = array ('host' => '127.0.0.1',
'username' => 'rob',
'password' => '******',
'dbname' => 'zfia');
$db = Zend_Db::factory('PDO_MYSQL', $params);
The Zend_Db abstraction is mostly built upon PHP??™s PDO extension which supports a wide range of
databases. There is also support for DB2 and Oracle outside of PDO, though as they all extend from
Zend_Db_Adapter_Abstract, the interface is essentially the same, regardless of the underlying database.
So, what you do get in Zend_Db that you don??™t get in PDO itself then? Well, you get lots of helper
functions to manipulate the database and also a profiler to work out why your code is so slow! There are all the
standard functions for inserting, updating and deleting rows, along with fetching rows.


Pages:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73