php创立一个mysql数据库_PHP代码创建Mysql数据库

文件名“config.php”,在其他文件中都被引用。“config.php”执行后出现“Couldnotopendatabasepleasecheckyoursettingsinconfig.php”。下面是可能涉及到得代码:$server="localhos...

文件名“config.php”,在其他文件中都被引用。“config.php”执行后出现“Could not open database

please check your settings in config.php”。下面是可能涉及到得代码:

$server = "localhost";

$username = "root";

$password = "123";

$database = "database_cs";

$ranks = array(

1=>"newbie",

2=>"new member",

3=>"member",

4=>"high member",

5=>"very high member",

6=>"supreme member",

7=>"ultra member",

8=>"godlike member",

9=>"god member",

10=>"low god",

11=>"medium god",

12=>"high god",

13=>"very high god",

14=>"supreme god",

15=>"ultra god",

16=>"perfect"

);

$couldNotOpenDatabase = "Could not open database
\n please check your settings in config.php";

f ($database == ""){

// Check it the database exist

$query = "use database_cs";

// If this query is succesfull, and returns a 1. this means that the database members can be used.

// If it returns 'null' then it doesn't exist.

if (mysql_query($query) == null){

//if it doesn't exist we create it and connect to it.

$query = "CREATE DATABASE database_cs";

$result = mysql_query($query);

if ($result == 1){

$conn = mysql_connect($server,$username,$password) or die ($couldNotConnectMysql);

mysql_select_db($database,$conn) or die ($couldNotOpenDatabase);

}else{echo "Error while creating database (Errornumber ". mysql_errno() .": \"". mysql_error() ."\")
";}

}

else{

// It already exist so we will connect to it.

$database= "database_cs";

$conn = mysql_connect($server,$username,$password) or die ($couldNotConnectMysql);

mysql_select_db($database,$conn) or die ($couldNotOpenDatabase);

//echo "数据库选择成功了!";

}

}

else{

// connect or show an error.

$conn = mysql_connect($server,$username,$password) or die ($couldNotConnectMysql);

mysql_select_db($database,$conn) or die ($couldNotOpenDatabase);

}

没有分了,哪位高手帮忙分析下,谢了。现在在做毕业设计“网上选课系统”,在网上下载的代码。比较急,各位救救急。

“$database=database_cs;”这条代码应该屏蔽掉;Mysql密码是“123”;

然后测试出现下面的错误提示:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\AppServ\www\ISC\config.php on line 92

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\AppServ\www\ISC\config.php on line 92

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\AppServ\www\ISC\config.php on line 95

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\AppServ\www\ISC\config.php on line 95

Error while creating database (Errornumber 1045: "Access denied for user 'ODBC'@'localhost' (using password: NO)")

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值