What is mysql_fetch_assoc equivalant in ZF?
You have several possibilities
using a plain db adapter, reference:
$db->setFetchMode(Zend_Db::FETCH_ASSOC);
$result = $db->fetchRow('SELECT * FROM bugs WHERE bug_id = 2');
// also works
$result = $db->fetchRow('SELECT * FROM bugs WHERE bug_id = 2', array(), Zend_Db::FETCH_ASSOC);
// note that $result is a single object, not an array of objects
echo $result['bug_description'];
using a table class, reference
$table = new Bugs();
$select = $table->select()->where('bug_status = ?', 'NEW')
->order('bug_id');
$row = $table->fetchRow($select);
$rowArray = $row->toArray();
Try with:
$table->fetchRow($select)->toArray();
If you have initialized a database connection, you can request it by
$db = Zend_Db_Table::getDefaultAdapter();
Now you can use the db adapter to query your results, and get it with mysql_fetch_assoc
using Zend_Select
$select = $db->select()
->from('table')
->where('id = ?', 5);
// mysql_fetch_assoc
$row = $db->fetchRow($select);
print_r($row);
Using manual SQL query
// mysql_fetch_assoc
$row = $db->fetchRow("SELECT * FROM table WHERE id = 5");
print_r($row);
Fetching multiple rows
use fetchAll method, which will return a assoc array with the results.
$db->fetchAll( "SELECT * FROM table ORDER BY id DESC );