gpt4 book ai didi

php - codeigniter 中的 mysql_fetch_row

转载 作者:行者123 更新时间:2023-11-29 19:18:46 27 4
gpt4 key购买 nike

如何在codeigniter中使用mysql_fetch_row?在 php 中,当我用户 mysql_fetch_row 时,我会得到这样的结果

$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
echo $row[1]; // the email value

我可以获取带有数字类型索引的数组。

但是当我像这样使用 codeigniter 时

$db=$this->load->database($_SESSION['DB'], TRUE);
$q=$db->query("select ID, Name from mdashboard");
foreach($q->result_array() as $d)
{
echo $d['ID'];
}

我得到带有字符串类型索引的数组。

Codeigniter 可以像我的第一个代码一样吗?

最佳答案

在 codeigniter 中使用 mysql get result 作为数组,你可以做到这一点

use result_array() get result  or use row_array() get number
public function getBy($where = array(), $field = '*')
{
$this->db->select($field);
$query = $this->db->get_where($this->table_name, $where);
if (!$query) {
return array();
}
return $query->result_array();
}

关于php - codeigniter 中的 mysql_fetch_row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42549987/

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