2011-05-23 139 views
7

我刚开始使用WAMP的PHP项目,我与这行代码有关的下一个错误:“数据过早结束”错误与PHP

$link=mysql_connect("localhost","myuser","mypas"); 

我读我不得不这样做用我的旧密码再次SET PASSWORD,但在重新启动所有服务后它仍然不起作用。我使用PHP 5.3.4和MySQL 5.1.53有什么帮助?感谢

Warning: mysql_connect() [function.mysql-connect]: Premature end of data (mysqlnd_wireprotocol.c:554) in C:\wamp\www\CDE\includes\baseDatos.php on line 5 
Call Stack 
1 0.0002 667312 {main}() ..\index.php:0 
2 0.0008 682416 include('C:\wamp\www\CDE\includes\seguridad.php') ..\index.php:2 
3 0.0010 690984 include('C:\wamp\www\CDE\includes\baseDatos.php') ..\seguridad.php:2 
4 0.0014 692368 mysql_connect () ..\baseDatos.php:5 

(!) Warning: mysql_connect() [function.mysql-connect]: OK packet 1 bytes shorter than expected in C:\wamp\www\CDE\includes\baseDatos.php on line 5 
Call Stack 
1 0.0002 667312 {main}() ..\index.php:0 
2 0.0008 682416 include('C:\wamp\www\CDE\includes\seguridad.php') ..\index.php:2 
3 0.0010 690984 include('C:\wamp\www\CDE\includes\baseDatos.php') ..\seguridad.php:2 
4 0.0014 692368 mysql_connect () ..\baseDatos.php:5 

(!) Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file in C:\wamp\www\CDE\includes\baseDatos.php on line 5 
Call Stack 
1 0.0002 667312 {main}() ..\index.php:0 
2 0.0008 682416 include('C:\wamp\www\CDE\includes\seguridad.php') ..\index.php:2 
3 0.0010 690984 include('C:\wamp\www\CDE\includes\baseDatos.php') ..\seguridad.php:2 
4 0.0014 692368 mysql_connect () ..\baseDatos.php:5 
+0

请贴的'在http baseDatos.php'代码:// www.ideone.com'和这里的链接。 – diEcho 2011-05-23 15:39:03

+0

也许还可以查看[Windows 7 PHP MySQL连接问题](http://stackoverflow.com/questions/4807072/windows-7-php-mysql-connection-issues)。 – 2011-05-23 15:40:36

+0

baseDatos.php只是一个“包含文件”,包含以下信息:http://www.ideone.com/pOvt9。如果它有帮助,从mysql.user做SELECT密码我得到一个16字节的密码,而不是原来的“mypas”。 – Arturo 2011-05-23 16:01:50

回答

5

我有同样的问题,并使用UPDATE查询像这个固定:

UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE Host = 'some_host' AND User = 'some_user'; 

不知道为什么,但设置的密码没有工作。

可以肯定,这个问题是一个我认为你应该做的MySQL数据库对这个查询:

SELECT 
`user`.`Password` 
FROM 
`user` 
WHERE 
`user`.`User` = 'youruser' AND 
`user`.`Host` = 'yourhost' 

如果密码不以启动*的问题是,你仍然有老encription

编辑_这里是一个PHP函数来创建MYSQL有效的密码(从here拍摄):

function mysql_41_password($in) 
{ 
$p=sha1($in,true); 
$p=sha1($p); 
return "*".strtoupper($p); 
} 

Thene你可以设置密码手动:

//newpwd is the passowr dgenerated in php 
UPDATE mysql.user SET Password = 'newpwd' WHERE Host = 'some_host' AND User = 'some_user'; 
FLUSH PRIVILEGES; 
+0

我做到了,我的密码是038872231aa1b123。我如何更改为新加密?谢谢 – Arturo 2011-05-23 15:54:58

+0

您确定您的ini文件中没有旧密码之类的东西吗? – 2011-05-23 16:13:16

+0

很确定,我搜索my.ini和php.ini没有结果... – Arturo 2011-05-23 16:17:31

0

您连接到本地主机建议您可能没有网络问题。

First hit in Google列出2种可能的原因/补救措施。当一个人使用PHP 5.3 ... ...与旨在与PHP 5.2中使用MySQL数据库......我注意到,当我换到另一个 版本的统一服务器的

出现此消息。

如果你没有访问数据库,并且主要使用这个远程连接来实现开发目的(像我一样),解决方案是使用PHP版本(目前最新的带有PHP 5.2的Uniform Server)进行配置。 ..似乎是PHP 5.2.13的5.6b-Nano)。

+2

我试过了,但没有“my.cnf”文件。只是一个“my.ini”,它没有任何“old_passwords”行。 – Arturo 2011-05-23 16:05:18

4

上述问题是由于PHP和MySQL之间的版本内兼容性而发生的。大多数情况下,它可能会在数据库远程访问期间发生

请检查您的PHP和MySQL版本。

我的版本是PHP-5.3.6(本地机器)和MySQL 5.1.56(Live DB)。

我的MySQL被放置在活动域中,我把我的PHP文件保存在本地机器中。我面临着相同的密码休息问题。

然后我用旧版本替换我的XAMPP,它将我的PHP版本更改为5.3.0。现在上述问题已解决,我可以从本地访问活动数据库。

0

如果使用MySQL 4。1 +试试这个

在MySQL命令行

mysql> set old_passwords = 0; mysql> set password for 'user'@'some.host.domain' = PASSWORD('new_pass'); mysql> set old_passwords = 1;