无法连接到mysql数据库[phpmyadmin] [英] Cannot connect to mysql database [phpmyadmin]
本文介绍了无法连接到mysql数据库[phpmyadmin]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 使用xampp-> phpyadmin创建数据库,
- 我创建了一个名为地牢"的数据库,
-
在我的php代码中,我使用以下代码连接到MySQL:
- 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());
错误消息说
选择数据库时,未知数据库'地牢'.
Unknown database 'dungeons', when selecting db.
我不知道问题出在哪里,因为已经建立了数据库并且我已经用代码成功连接到了mysql.
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.
推荐答案
错误正确地表明数据库不可用或不存在. 首先在phpmyadmin中创建一个新数据库,并将其命名为dungeons.之后,尝试您的脚本. 谢谢
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
这篇关于无法连接到mysql数据库[phpmyadmin]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文