用户'@'localhost'拒绝访问数据库'waqas'codeigniter

时间:2019-03-16 16:33:26

标签: php codeigniter

我想使用database创建一个CodeIgniter。我已经编写了这段代码。

 $template = 'application/views/install/db/dbwrite.php';
 $template_path =  set_realpath($template);
 $output_path   = 'application/config/database.php';
 $database_file = file_get_contents($template_path);
 $new  = str_replace("%HOSTNAME%",$_POST['dbhost'],$database_file);
 $new  = str_replace("%USERNAME%",$_POST['username'],$new);
 $new  = str_replace("%PASSWORD%",$_POST['password'],$new);
 $new  = str_replace("%DATABASE%",$_POST['dbname'],$new);
 $dbName = $_POST['dbname'];
 $sql = "CREATE DATABASE IF NOT EXISTS $dbName";
 $this->db->query($sql);
 $handle = fopen($output_path,'w+');
 fwrite($handle,$new); 

此处$_POST['username']的值为root,而$_POST['password']的值为''。但是$sql = "CREATE DATABASE IF NOT EXISTS $dbName";却给我这个错误。并且mysql默认的usernamerootpassword''

Error Number: 1044

Access denied for user ''@'localhost' to database 'waqas'

CREATE DATABASE IF NOT EXISTS waqas

Filename: D:/xampp/htdocs/ci_api/system/database/DB_driver.php

Line Number: 691

0 个答案:

没有答案
相关问题