Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Codeigniter:“;“未找到表格”;创建数据库后插入数据时出错_Mysql_Codeigniter - Fatal编程技术网

Mysql Codeigniter:“;“未找到表格”;创建数据库后插入数据时出错

Mysql Codeigniter:“;“未找到表格”;创建数据库后插入数据时出错,mysql,codeigniter,Mysql,Codeigniter,我正在为我的Codeigniter应用程序制作一个安装程序模块 我正在通过代码创建MySQL数据库及其表,并希望在安装过程中将用户凭据插入数据库。像这样: 我遇到的问题是,在创建数据库及其表之后,当我尝试将用户信息插入数据库时,会出现错误,说“表‘user’不存在”,而表实际存在 代码如下: $this->load->dbforge(); //Create the database $this->install_model->use_sql_string(); /

我正在为我的Codeigniter应用程序制作一个安装程序模块

我正在通过代码创建MySQL数据库及其表,并希望在安装过程中将用户凭据插入数据库。像这样:

我遇到的问题是,在创建数据库及其表之后,当我尝试将用户信息插入数据库时,会出现错误,说“表‘user’不存在”,而表实际存在

代码如下:

$this->load->dbforge();  //Create the database
$this->install_model->use_sql_string();   //Add the tables from a .sql file

$this->load->database($database_name);  //Load the created database

$this->install_model->add_the_user($username, $password));  //Insert user data
正在正确创建数据库和表。只有最后一行代码给出了错误


我不知道我做错了什么。请帮忙

我认为您应该先加载数据库,然后再导入.sql文件。 所以表将在加载的数据库中创建

$this->load->dbforge();  //Create the database
$this->load->database($database_name);  //Load the created database
$this->install_model->use_sql_string();   //Add the tables from a .sql file
$this->install_model->add_the_user($username, $password));  //Insert user data

$database\u name
在哪里?它包含什么?
$database\u name
来自$\u POST(表单),它得到了用户输入的数据库的名称。我不知道CI中的语法,但在DB创建后运行一个查询
使用DBName
@Mihai
$this->load->database($DB\u name)
执行与使用DBName相同的操作