php连接数据库出现问题 30
<html><head><title></title><metahttp-equiv="Content-Type"content="text/html;charset=U...
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$db="phpdev";
$con = mysql_connect("localhost:3306","root"," ");
// Create table in my_db database
mysql_select_db($db);
$query="select*from symbols";
$result=mysql_query($query);
if(mysql_num_rows($result)>0){
echo "<table cellpadding=10 border=1>";
while($row=mysql_fetch_row($result)){
echo"<tr>";
echo"<td>".$row[0]."</td>";
echo"<td>".$row[1]."</td>";
echo"<td>".$row[2]."</td>";
echo"</tr>";
}
echo"</table>";
}
else{
echo"记录未找到!";
}
mysql_close($connection);
?>
</body>
</html>
然后运行出现以下这个
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 10
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 14
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\xampplite\htdocs\NewPhpProject\dt.php on line 14
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 16
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampplite\htdocs\NewPhpProject\dt.php on line 16
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\NewPhpProject\dt.php on line 17
记录未找到!
Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\NewPhpProject\dt.php on line 32
这怎么回事呢?请高人指点一下
数据库里有东西啊
我用得是netbeans+xampp来搭建的。
如果数据库里面没东西,除了“记录未找到”这个显示之外,应该不会出现以上那些warning 吧? 展开
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$db="phpdev";
$con = mysql_connect("localhost:3306","root"," ");
// Create table in my_db database
mysql_select_db($db);
$query="select*from symbols";
$result=mysql_query($query);
if(mysql_num_rows($result)>0){
echo "<table cellpadding=10 border=1>";
while($row=mysql_fetch_row($result)){
echo"<tr>";
echo"<td>".$row[0]."</td>";
echo"<td>".$row[1]."</td>";
echo"<td>".$row[2]."</td>";
echo"</tr>";
}
echo"</table>";
}
else{
echo"记录未找到!";
}
mysql_close($connection);
?>
</body>
</html>
然后运行出现以下这个
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 10
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 14
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\xampplite\htdocs\NewPhpProject\dt.php on line 14
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampplite\htdocs\NewPhpProject\dt.php on line 16
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampplite\htdocs\NewPhpProject\dt.php on line 16
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\NewPhpProject\dt.php on line 17
记录未找到!
Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\NewPhpProject\dt.php on line 32
这怎么回事呢?请高人指点一下
数据库里有东西啊
我用得是netbeans+xampp来搭建的。
如果数据库里面没东西,除了“记录未找到”这个显示之外,应该不会出现以上那些warning 吧? 展开
4个回答
展开全部
$result=mysql_query($query);
改为$result=@mysql_query($query);可以屏蔽警告!
然后可以在代码中判断$result是否为空并进行处理。
改为$result=@mysql_query($query);可以屏蔽警告!
然后可以在代码中判断$result是否为空并进行处理。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你增加一条记录就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你数据库里面有东西么?是空的吧?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询