php - 而不是 'mysql_fetch_assoc' - Codeigniter

标签 php mysql codeigniter

我是 codeigniter 的新手。我已经阅读了事件记录并完成了以下代码:

header("Content-Type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies

$output = fopen('php://output', 'w');

fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));

$this->db->select('field_id_1, field_id_2, field_id_3');
$query = $this->db->get('exp_channel_data');    

$rows = $query->result_array();     

while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);

在此代码块末尾的while语句中,我不确定使用什么来代替mysql_fetch_assoc

我已将数据库结果输出到变量$rows中。

应该用什么来替换while语句中的mysql_fetch_assoc

谢谢。

最佳答案

当您使用 result_array() 时。因此 $rows 以数组形式给出结果,您可以使用 foreach 循环从 $rows 中提取数据,例如 foreach($rows as $row)。

关于php - 而不是 'mysql_fetch_assoc' - Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27930773/

相关文章:

php - 正则表达式 - 查找 <td> 标签之间的所有内容

php - SoapServer,handle() 错误 - 过程未设置

php - 无法从 WAMP 登录 MySQL,但可以登录 MariaDB

php - 你能给助手一个变量并更改它在 CodeIgniter 中使用的函数吗

mysql - Codeigniter - Active Records 是否容易受到 SQL 注入(inject)攻击?

php - codeigniter 提示和技巧

php - 无法安装 mbstring php...缺少 libgmp.so.3

php - MySQL 查询在 Laravel 中不起作用,但在 mysqli_* 中工作正常

php - 按顺序更改组

php - 不重复重复获取MYSQL结果