gpt4 book ai didi

php - 从sql php获取所有数据

转载 作者:行者123 更新时间:2023-11-29 13:50:49 25 4
gpt4 key购买 nike

我想获取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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com