我的表user
如下:
| user_id | first_name | moniker |
| 1 | Noah | noahsarkive |
| 2 | Homer | HomerK |
| 3 | Hot | Inflated |
| 4 | Wimpy | Wimpy B |
| 5 | Hubble | SharpEyes |
模型是User_model.php:
<?php
if ( ! defined('BASEPATH')) {
exit('No direct script access allowed');
}
class User_model extends CI_Model
{
public function __construct() {
parent::__construct();
}
public function get_users() {
$this->db->select('user_id','first_name', 'moniker');
$this->db->from('user');
$rs = $this->db->get();
var_dump($rs);
return $rs;
}
}
但是当我执行 var_dump($rs)
时,它会产生:
object(CI_DB_mysql_result)#25 (8) {
["conn_id"]=>
resource(25) of type (mysql link persistent)
["result_id"]=>
resource(36) of type (mysql result)
["result_array"]=>
array(0) {
}
["result_object"]=>
array(0) {
}
["custom_result_object"]=>
array(0) {
}
["current_row"]=>
int(0)
["num_rows"]=>
int(5)
["row_data"]=>
NULL
}
它返回正确的行数但没有数据! 不能再简单了,但我一定遗漏了一些非常明显的东西。
感谢您的帮助。 诺亚
最佳答案
您需要对结果对象做一些事情,like so :
$rs = $this->db->get();
foreach ($rs->result() as $row)
{
echo $row->user_id;
echo $row->first_name;
echo $row->moniker;
}
关于mysql - Codeigniter db->get() 返回空记录集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28532909/