i want to use zend_db standalone cos zend framework is too much for my project but i'm new with it, is it correct to do this:
$pdoParams = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8;');
$params = array( 'host' => 'localhost', 'username' => 'ss_fraat', 'password' => 'jos10', 'dbname' => '_a2hDB', 'driver_options' => $pdoParams ); try { $db = Zend_Db::factory('PDO_MYSQL', $params); //set default adapter Zend_Db_Table_Abstract::setDefaultAdapter($db); } catch (Exception $e) { exit($e->getMessage()); } //save Db in registry for later use Zend_Registry::set('dbAdapter', $db);
then in any class do this:
$db = Zend_Registry::get('db');
/** quote to avoid sql injection */
$date = $db->quote('1980-01-01');
$sql = 'SELECT * FROM product WHERE name = ' . $date;
$result = $db->query($sql);
$db->query(); //run a query
i really need to do this
Zend_Db_Table_Abstract::setDefaultAdapter($db);
i get this code from a website, is it necessary to use Zend_Db_Table_Abstract if i'm not using the full zend framework, or it is better for example to use this:
$db = Zend_Db::factory( ...options... ); $select = new Zend_Db_Select($db);
what i want is to setup a pdo/mysql connexion in my bootstrap php page and be able to get that db instance in any class without starting a new connexion to execute queries but i'm not sure how to do that use Zend_Db_Table_Abstract or Zend_Db_Select use the registry Zend_Registry::set('dbAdapter', $db) or not thanks a lot