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

    报告相同问题?

    悬赏问题

    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多
    • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
    • ¥15 有赏,i卡绘世画不出
    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入
    • ¥40 使用MATLAB解答线性代数问题
    • ¥15 COCOS的问题COCOS的问题
    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败