我想在mysql中的表travel_location中获取所有位置。这是我的代码
$select = $this->_db_table->select()->from(travel_location, array('*'));
$result = $this->_db_table->fetchAll($select);
if(count($result) == 0) {
throw new Exception('not found',404);
}
while ($row1 = mysql_fetch_array($result)){
$user_object = new Api_Model_User($row1);
$count = 1;
$json = array($json[$count] = array(
'travel_location_id' => $user_object->travel_location_id,
'city_id' => $user_object->city_id,
'user_id' => $user_object->user_id,
'location_name' => $user_object->location_name,
'description' => $user_object->description,
'longitude' => $user_object->longitude,
'latitude' => $user_object->latitude,
'created_time' => $user_object->created_time,
'updated_time' => $user_object->updated_time));
$count++;
}
没用我打印$ row1 = mysql_fetch_array($ result)并返回false,所以我认为这是错误的,因为这行。我该如何解决?
最佳答案
如果使用Zend_Db_Table中的fetchAll
,则会得到Zend_Db_Table_Rowset。
尝试这个:
foreach ($result as $row) {
// $row should be a Zend_Db_Table_Row object
// you can cast to array
$rowArray = $row->toArray();
$user_object = new Api_Model_User($rowArray);
}
阅读有关here和here的更多信息
关于php - 从SQL PHP获取所有数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16700867/