when i try to construct a query to my db in my model like
class Application_Model_DbTable_Resume extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
public function getFiveLastResume (){
$select= $db->select()->from('users')->order("id DESC")->limit(5);
$stmt = $db->query($select);
$row = $stmt->fetchAll();
return $row;
}
}
so i have an error Notice: Undefined variable: db
if I write adapter before query
$db = Zend_Db::factory('PDO_MYSQL',array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'dbname' => 'sport'
));
thats work good. why does my adapter not work ?
my application.ini contain right database config,cuz more simply queries work out good without including adapter. im noob in zend, thanks
$dbis undefined in the local scope which is why you get the error.Since you are inside a
DbTableobject, you can use$thisto get the DB adapter:Anywhere else in your application, you should be able to get a reference to the default DB adapter using:
This of course assumes you have created a
Zend_Db_Tableobject and set it as the default adapter.