我正在尝试从数据库中获取一行,但是当它返回下面的内容而不是正确的数组时。
Zend_Db_Table_Row Object
(
[_data:protected] => Array
(
[Id] => 1
[firstname] => Tuhin
[lastname] => Biswas
[email] => tuhin@gmail.com
)
[_cleanData:protected] => Array
(
[Id] => 1
[firstname] => Tuhin
[lastname] => Biswas
[email] => tuhin@gmail.com
)
[_modifiedFields:protected] => Array
(
)
[_table:protected] => Application_Model_DbTable_Client Object
(
[_name:protected] => client
[_definition:protected] =>
[_definitionConfigName:protected] =>
[_db:protected] => Zend_Db_Adapter_Pdo_Mysql Object
(
[_pdoType:protected] => mysql
[_numericDataTypes:protected] => Array
(
[0] => 0
[1] => 1
[2] => 2
[INT] => 0
[INTEGER] => 0
[MEDIUMINT] => 0
[SMALLINT] => 0
[TINYINT] => 0
[BIGINT] => 1
[SERIAL] => 1
[DEC] => 2
[DECIMAL] => 2
[DOUBLE] => 2
[DOUBLE PRECISION] => 2
[FIXED] => 2
[FLOAT] => 2
)
答案 0 :(得分:2)
它不会自动返回数组, 如果你愿意,你可以在模型中使用以下
public function getRow($id)
{
$id = (int)$id;
$row = $this->fetchRow('id = ' . $id);
if (!$row) {
throw new Exception("Could not find row $id");
}
return $row->toArray();
}
或直接来自控制器
在fetchrow之后调用toArray(),
喜欢$result=$model->fetchRow($where)->toArray();
答案 1 :(得分:1)
你正在使用Zend库,它不应该返回一个数组。请参阅文档:
http://framework.zend.com/manual/1.12/en/zend.db.table.row.html#zend.db.table.row.read
如果您想将行作为数组使用,请从上面开始:
$row->toArray();