A simple example of using Zend Framework Zend_Db_Table

To be a professional PHP developer, framework probably is a final solution. Since ZF is Zend’s product, I think it would not be a bad idea if I learn it even I’m not sure which framework is better. Anyway, the best learning approach is to start studying right now. Here is my first practice example.

ini_set('display_errors', true);
$rootDir = dirname(dirname(__FILE__));
//echo dirname(__FILE__); C:\wamp\www\zf-tutorial\testdb
//echo $rootDir;          C:\wamp\www\zf-tutorial
set_include_path( $rootDir . '/library'. PATH_SEPARATOR . get_include_path());
$params = array (
	'host' => 'localhost',
	'username' => 'root',
	'password' => 'admin',
	'dbname' => 'zf-tutorial'
$db = Zend_Db::factory('PDO_MYSQL', $params);
class Albums extends Zend_Db_Table_Abstract
	protected $_name = 'albums';
$albums = new Albums();
$data = array(
        'artist' => 'Ben',
        'title' => 'Ramsey'
$id = $albums->insert($data);

Of course, you should have a database table setup on your local machine first.

Leave a Comment