Cannot connect to mysql database [phpmyadmin]

纵饮孤独 提交于 2019-12-12 03:48:56

问题


  • to create databases I'm using xampp->phpyadmin,
  • I have created a database called "dungeons",
  • in my php code Im connecting to MySQL with this code:

    if ($_SERVER["SERVER_ADDR"]=="localhost")
    {
      define("SQL_HOST","localhost");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME",xxx);
      define("SQL_PASSWORD",xxx);
    } else {
      define("SQL_HOST","127.0.0.1");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME", xxx);
      define("SQL_PASSWORD",xxx);
    }
    
    mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD) or die("Cannot connect to mySQL: " . mysql_error());
    mysql_select_db(SQL_DBNAME) or die("Cannot connect to the database: ". mysql_error()); 
    

The error message says

Unknown database 'dungeons', when selecting db.

I don't have any idea where the problem is, since the database is made and I have successfully connected to the mysql with the code.


回答1:


The error is correctly saying that the database is not available or not there. First create a new database in phpmyadmin and name it dungeons. After that try your script. Thank you




回答2:


The error message says

Unknown database 'dungeons'

There doesn't exist a database with name "dungeons".

First create a database using

create database dungeons;


来源:https://stackoverflow.com/questions/15449721/cannot-connect-to-mysql-database-phpmyadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!