PHP代码创建Mysql数据库

[复制链接]
查看11 | 回复2 | 2010-5-26 13:52:53 | 显示全部楼层 |阅读模式
文件名“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)")

回复

使用道具 举报

千问 | 2010-5-26 13:52:53 | 显示全部楼层
先mysql_connect()到mysql再做mysql_query()的相关操作。===================================================================="newbie",2=>"new member",3=>"member",4=>"high member",5=>"very high member",
回复

使用道具 举报

千问 | 2010-5-26 13:52:53 | 显示全部楼层
问题出在两行 $conn = mysql_connect($server,$username,$password) or die ($couldNotConnectMysql); mysql_select_db($database,$conn) or die ($couldNotOpenDatabase);,问题可能出现在你的,$username,$
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行