dounao5856 2019-03-16 16:33
浏览 140

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

I want to create a database using CodeIgniter. I have written this code.

 $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); 

here the value of $_POST['username'] is root and $_POST['password'] is ''. but the $sql = "CREATE DATABASE IF NOT EXISTS $dbName"; it gives me that error. and also mysql default username is root and password is ''.

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog