Php 错误号1046:在Codeigniter中未选择数据库
这个Php 错误号1046:在Codeigniter中未选择数据库,php,codeigniter,Php,Codeigniter,这个函数运行\u blank\u sql()是我为将sql文件安装到数据库中而创建的。 但是这个代码$this->load->database()给了我一个错误。 未选择任何数据库 我还自动加载了数据库$autoload['libraries']=array('database','session') 而且数据库在config/database.php 'hostname' => 'localhost', 'username' => 'root', 'password' =>
函数运行\u blank\u sql()
是我为将sql文件安装到数据库中而创建的。
但是这个代码$this->load->database()代码>给了我一个错误。
未选择任何数据库
我还自动加载了数据库<代码>$autoload['libraries']=array('database','session')代码>
而且数据库
在config/database.php
'hostname' => 'localhost',
'username' => 'root',
'password' => '********',
'database' => 'waqas',
'dbdriver' => 'mysqli',
而数据库
也是在Mysql
中创建的
function run_blank_sql() {
$this->load->database();
// Set line to collect lines that wrap
$templine = '';
// Read in entire file
$lines = file('./uploads/install.sql');
// Loop through each line
foreach ($lines as $line) {
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current templine we are creating
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query so can process this templine
if (substr(trim($line), -1, 1) == ';') {
// Perform the query
$this->db->query($templine);
// Reset temp variable to empty
$templine = '';
}
}
}
我认为您尚未为项目选择任何默认数据库。这就是为什么会出现这个错误。要选择数据库,应至少指定一个。数据库主要加载在构造函数中。因此,现在修改您的代码如下
$this->db = $this->load->database("default",TRUE);
我认为您尚未为项目选择任何默认数据库。这就是为什么会出现这个错误。要选择数据库,应至少指定一个。数据库主要加载在构造函数中。因此,现在修改您的代码如下
$this->db = $this->load->database("default",TRUE);
检查您的密码。。!可能无效。这看起来像是数据库配置文件中的安装错误,您使用的是哪个CI版本?您是在本地主机上还是在生产服务器上使用它?和:如何创建数据库(通过cpanel或编程?)检查密码。。!可能无效。这看起来像是数据库配置文件中的安装错误,您使用的是哪个CI版本?您是在本地主机上还是在生产服务器上使用它?以及:如何创建数据库(通过cpanel还是通过编程?)