php - 从sql php获取所有数据

标签 php mysql database zend-framework

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

相关文章:

php - 多重核算

php - MySQL 对多个表进行合并和加权排序

php - 将 datetimepicker 插件格式化为 jQuery datepicker 以在 MySQL 中使用

php - php 中的 mysql.connect_timeout 与 mysql 中的 connect_timeout

mysql - 我如何得到这个:through?

php - Windows 8 应用程序 C# 与 PHP 和 Mysql

MySQL关系

html - 如何在我的 PHP 文件中引用我的 MySQL 数据库之一?

mysql - SQL:假设,如果将不合适的数字添加到唯一标识符列,会发生什么情况?

php - 如何从 PHP 脚本与 python 守护进程通信