C3rd
Zend Framwork: Accessing Database in different ways
Posted: 8 May 2012, 13:11pm - TuesdayAssuming I declared some variables in application.ini named webbyConfig and initialized in Bootstrap.php;
$config = Zend_Registry::get('webbyConfig'); $this->_db = new Zend_Db_Adapter_Pdo_Mysql(array( 'host' => $config['db_host'], 'username' => $config['db_user'], 'password' => $config['db_passwd'], 'dbname' => $config['db_name'], )); .... $sql = 'SELECT a.col1,b.col2 FROM tableA AS a, tableB AS b WHERE a.id = b.id AND a.id = 1'; $stmt = $this->_db->query($sql); print_r($stmt->fetchAll());and this is another way accessing the db...
$sql = 'SELECT a.col1,b.col2 FROM tableA AS a, tableB AS b WHERE a.id = b.id AND a.id = 1'; $db = Zend_Db_Table::getDefaultAdapter(); $stmt = $db->query($sql); print_r($stmt->fetchAll());That's what I know so far... I think there's more... still exploring ZF. :)