7

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 
  • please paste the code of `baseDatos.php` on http://www.ideone.com` and link here. – xkeshav May 23 '11 at 15:39
  • Perhaps also check out [Windows 7 PHP MySQL Connection Issues](http://stackoverflow.com/questions/4807072/windows-7-php-mysql-connection-issues). – Brad Christie May 23 '11 at 15:40
  • baseDatos.php is just an "include file" with this information: http://www.ideone.com/pOvt9. If it helps, doing SELECT password from mysql.user I get a 16 bytes password instead of the original "mypas". –  May 23 '11 at 16:01
  • 1
    **Premature end of data** is also know as **premature finalization**. *(sorry, couldn't help myself)* – CodeAngry Jul 24 '13 at 15:04

4 Answers4

5

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.

Hafenkranich
  • 1,696
  • 18
  • 32
Sankar Subburaj
  • 4,992
  • 12
  • 48
  • 79
4

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;
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
  • I did that and my password is 038872231aa1b123. How do I change to new encryption? THANKS –  May 23 '11 at 15:54
  • Are you sure that you don't have something like old-passwords in your ini file? – Nicola Peluchetti May 23 '11 at 16:13
  • 1
    Well you can generate a valid password in php and set it with an update query then, i updated my answer to show how to do it. Hope it helps – Nicola Peluchetti May 23 '11 at 16:19
  • I am using remote server, resolve this type issues by using the above method needs root access(SSH) of the server. Most of the clients didn't give those secure details. Otherwise it is very easy and quick way to resolved the reset password issue. – Sankar Subburaj Jan 04 '12 at 12:24
0

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;

0

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).

Hafenkranich
  • 1,696
  • 18
  • 32
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 2
    I tried that but I have no "my.cnf" file. Just a "my.ini" and it does not have any "old_passwords" line. –  May 23 '11 at 16:05