“数据提前结束” PHP 错误

发布于 2024-11-09 09:08:00 字数 1907 浏览 0 评论 0原文

我刚刚开始在 PHP 项目中使用 WAMP,我收到与这行代码相关的下一个错误:

$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 

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");

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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柠檬心 2024-11-16 09:08:00

出现上述问题是由于PHP和MySQL版本不兼容造成的。大多数情况下可能发生在远程访问数据库期间。

请检查您的 PHP 和 MySQL 版本。

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

我的 MySQL 放置在实时域中,我将 PHP 文件保存在本地计算机中。我遇到了同样的密码重置问题。

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

The above problem occurs because of version in-compatibility between PHP and MySQL. Mostly it may occur during remote access of db.

Kindly check your PHP and MySQL versions.

My versions are PHP-5.3.6 (Local machine) and MySQL 5.1.56 (Live DB).

My MySQL is placed in live domain and I kept my PHP files in local machine. I faced the same password rest problem.

Then I replace my XAMPP with older version it changed my PHP version to 5.3.0. Now the above problem was solved and I am able to access the live db from local.

匿名的好友 2024-11-16 09:08:00

我遇到了同样的问题,并使用如下更新查询修复了它:

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'

如果密码不以 * 开头,问题是你仍然有旧的加密

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

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;

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.

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 _ 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;
≈。彩虹 2024-11-16 09:08:00

如果使用 MySQL 4.1 + 尝试

在 MySQL 命令行

mysql>设置old_passwords = 0;
mysql>为 'user'@'some.host.domain' 设置密码 = PASSWORD('new_pass');
mysql>设置old_passwords = 1;

If using MySQL 4.1 + Try this

At the MySQL Command line

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

长亭外,古道边 2024-11-16 09:08:00

您正在连接到本地主机表明您可能没有网络问题。

Google 中的首次点击列出了 2 个可能的原因/补救措施。

当使用 PHP 5.3...以及旨在与 PHP 5.2 一起使用的 MySQL 数据库时,会出现此消息...我注意到当我更改为另一个时
统一服务器版本。

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

That you are connecting to localhost suggests that you probably don't have network problems.

First hit in Google lists 2 possible causes/remedies.

This message appears when one is using PHP 5.3... with MySQL database that is intended to be used with PHP 5.2... I noticed that when I changed to another
version of Uniform Server.

If you don't have access to the database and are mainly using this remote connection to development purposes (like me) a solution to the is to have configurations with both PHP versions (currently the latest Uniform Server with PHP 5.2... appears to be 5.6b-Nano with PHP 5.2.13).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文