我最近从完美运行的 CodeIgniter v2.2.0 升级到 CodeIgniter v3.0.1 以获得更好的会话处理。这样做时,对数据库的所有调用,无论$database['dbdriver']
使用哪个,都不会返回任何内容。我也尝试过$config
像这样将数组直接输入到数据库加载器中:$this->load->database($config);
但这也不起作用。我尝试过使用 PDO 和 MySQLi 驱动程序,它们都返回相同的东西:
MySQLi:
string 'SELECT *
FROM `ns_users`' (length=24)
object(CI_DB_mysqli_result)[26]
public 'conn_id' =>
object(mysqli)[24]
public 'affected_rows' => null
public 'client_info' => null
public 'client_version' => null
public 'connect_errno' => null
public 'connect_error' => null
public 'errno' => null
public 'error' => null
public 'error_list' => null
public 'field_count' => null
public 'host_info' => null
public 'info' => null
public 'insert_id' => null
public 'server_info' => null
public 'server_version' => null
public 'stat' => null
public 'sqlstate' => null
public 'protocol_version' => null
public 'thread_id' => null
public 'warning_count' => null
public 'result_id' =>
object(mysqli_result)[25]
public 'current_field' => null
public 'field_count' => null
public 'lengths' => null
public 'num_rows' => null
public 'type' => null
public 'result_array' =>
array (size=0)
empty
public 'result_object' =>
array (size=0)
empty
public 'custom_result_object' =>
array (size=0)
empty
public 'current_row' => int 0
public 'num_rows' => null
public 'row_data' => null
PDO:
string 'SELECT *
FROM `ns_users`' (length=24)
object(CI_DB_pdo_result)[26]
public 'conn_id' =>
object(PDO)[23]
public 'result_id' =>
object(PDOStatement)[25]
public 'queryString' => string 'SELECT *
FROM `ns_users`' (length=24)
public 'result_array' =>
array (size=0)
empty
public 'result_object' =>
array (size=0)
empty
public 'custom_result_object' =>
array (size=0)
empty
public 'current_row' => int 0
public 'num_rows' => null
public 'row_data' => null
我试图运行的简单查询是,这样我就可以看到正在从数据库中提取数据:
SELECT * FROM `ns_users`
该表绝对不是空的,它包含超过 300 万条登录记录,我什至尝试将限制设置为 1,以防记录/数据量过多。
我是否遗漏了任何应该在我的配置中的东西?以下是我的配置(请记住,我设置了 CI 以在同一个 CI 安装上处理多个应用程序)
配置/数据库.php
<?php
$db['users'] = array(
'dsn' => 'mysql:host=localhost;dbname=apps_control',
'hostname' => 'localhost',
'username' => '***********',
'password' => '***********',
'database' => 'apps_control',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => TRUE,
'failover' => array(),
'save_queries' => TRUE
);
define('USERS_DB_GROUP', 'users');
控制器/test.php
<?php
class Test extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index(){
$this->load->model('Users');
var_dump($this->Users->get_all_users());
exit;
}
}
模型/users.php
<?php
class Users extends CI_Model {
private $table_name;
private $udb;
public function __construct() {
parent::__construct();
}
public function init($config = null){
if(!empty($config) && is_array($config))
$this->udb = $this->load->database($config, TRUE);
else
$this->udb = $this->load->database(USERS_DB_GROUP, TRUE);
if(!$this->table_name)
$this->table_name = $this->udb->dbprefix('ns_users');
}
public function get_all_users(){
$this->init();
$result = $this->udb->get($this->table_name);
var_dump($this->udb->last_query());
var_dump($result);exit;
if($result && $result->num_rows > 0){
return $result->result_array();
}
return false;
}
}
任何帮助表示赞赏,我只是不知道我在这里缺少什么。