“Premature end of data” error with PHP

前端 未结 4 1128
无人共我
无人共我 2020-12-06 07:29

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\",\"mypa         


        
相关标签:
4条回答
  • 2020-12-06 07:45

    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;
    
    0 讨论(0)
  • 2020-12-06 07:56

    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.

    0 讨论(0)
  • 2020-12-06 08:01

    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 讨论(0)
  • 2020-12-06 08:06

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

    0 讨论(0)
提交回复
热议问题