“数据提前结束"PHP错误 [英] "Premature end of data" error with PHP

查看:21
本文介绍了“数据提前结束"PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始将 WAMP 用于 PHP 项目,但出现了与这行代码相关的下一个错误:

I've just started using WAMP for a PHP project and I get the next errors related with this line of code:

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

我读到我必须使用旧密码再次执行 SET PASSWORD,但在重新启动所有服务后它仍然不起作用.我使用的是 PHP 5.3.4 和 MySQL 5.1.53 有什么帮助吗?谢谢

I read that I had to do the SET PASSWORD again with my old password, but it still does not work after restarting all services. I am using PHP 5.3.4 and MySQL 5.1.53 Any help? THANKS

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 

推荐答案

我遇到了同样的问题,并使用这样的 UPDATE 查询修复了它:

I had the same problem and fixed it using an UPDATE query like this:

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

不知道为什么,但设置密码不起作用.

Don't know why but SET Password didn't work.

为了确保问题出在我认为您应该在 mysql 数据库上执行此查询的问题:

To be sure that the problem is the one i think you should do this query on the mysql database:

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

如果密码不以 * 开头,则问题是您仍然使用旧密码

if the password doesn't start with a * the problem is that you still have the old encription

EDIT _ 这是一个为 MYSQL 创建有效密码的 php 函数(取自 此处):

EDIT _ Here is a php function to create valid password for MYSQL (taken from here):

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

然后你可以手动设置密码:

Thene you can set the password manually:

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

这篇关于“数据提前结束"PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆