冒昧的说一句,我感觉这个跟代码没关系,可能是配置的问题吧。 我新写了一个简单的,还是不行:<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html> <head> <title>Title here!</title> </head> <body> <?php $conn = mysql_connect("localhost", "root", "pwd"); echo $conn; mysql_close($conn); ?> </body> </html>结果:Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Program Files\Apache Group\Apache2\htdocs\TestDB.php on line 8Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Group\Apache2\htdocs\TestDB.php on line 10
你把你的连接语句替换成下面这样再执行一遍,把输出的错误信息贴出来看看: $link = mysql_connect('localhost', 'root', '821007') or die ('Not connected : ' . mysql_error());
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Program Files\Apache Group\Apache2\htdocs\TestDB_2.php on line 8 Not connected : Client does not support authentication protocol requested by server; consider upgrading MySQL client我的mysql版本:5.1.20-beta
mysql 新旧版本密码算法不一致导致第一种解决方法: mysql> SET PASSWORD FOR -> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');比方说数据库用户是admin,主机localhost,密码是123456这时候输入的命令应该是:mysql> SET PASSWORD FOR admin@localhost=OLD_PASSWORD('123456');第二种解决方法:mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd') -> WHERE Host = 'some_host' AND User = 'some_user'; mysql> FLUSH PRIVILEGES; 从网上一搜,答案大把大把的
不知道你当时是怎样修改root用户密码的,执行下面两条命令再试试(mysql.exe下面执行).SET PASSWORD FOR 'root'@'localhost' = OLD_PASSWORD('821007'); FLUSH PRIVILEGES;
先执行
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');另外,这是最基础的问题,还是认真看下PHP手册中 函数参考->MySQL函数库 中各个函数的详细说明及使用方法吧.
<? $conn=mysql_connect("localhost","root","821007");
mysql_select_db("test");
$sql="select * from pet";
$result=mysql_query($sql);
?><form name="form1" method="post" action="">
<table width="200" border="1">
<tr>
<td>Name</td>
<td>Owner</td>
<td>Species</td>
</tr>
<?
while($arr=mysql_fetch_array($result))
{
?>
<tr>
<td><?echo "$arr[name]";?></td>
<td><?echo "$arr[owner]";?></td>
<td><?echo "$arr[species]";?></td>
</tr>
<?}?>
</table>
</form>
你的错误提示中TestDB_2.php on line 8 是mysql_select_db
而你的代码根本就不是
<head>
<title>Title here!</title>
</head>
<body>
<?php $conn=mysql_connect("localhost","root","821007");
mysql_select_db("test");
$sql="select * from pet";
$result=mysql_query($sql);
?><form name="form1" method="post" action="">
<table width="200" border="1">
<tr>
<td>Name</td>
<td>Owner</td>
<td>Species</td>
</tr>
<?php
while($arr=mysql_fetch_array($result))
{
?>
<tr>
<td><?echo "$arr[name]";?></td>
<td><?echo "$arr[owner]";?></td>
<td><?echo "$arr[species]";?></td>
</tr>
<?php
}?>
</table>
</form>
</body>
</html>
我新写了一个简单的,还是不行:<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "root", "pwd");
echo $conn;
mysql_close($conn);
?>
</body>
</html>结果:Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Program Files\Apache Group\Apache2\htdocs\TestDB.php on line 8Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Group\Apache2\htdocs\TestDB.php on line 10
$link = mysql_connect('localhost', 'root', '821007') or die ('Not connected : ' . mysql_error());
Not connected : Client does not support authentication protocol requested by server; consider upgrading MySQL client我的mysql版本:5.1.20-beta
$conn = mysql_connect("127.0.0.1", "root", "pwd");
mysql 新旧版本密码算法不一致导致第一种解决方法:
mysql> SET PASSWORD FOR
-> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');比方说数据库用户是admin,主机localhost,密码是123456这时候输入的命令应该是:mysql> SET PASSWORD FOR admin@localhost=OLD_PASSWORD('123456');第二种解决方法:mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('newpwd')
-> WHERE Host = 'some_host' AND User = 'some_user';
mysql> FLUSH PRIVILEGES;
从网上一搜,答案大把大把的
FLUSH PRIVILEGES;