2011-05-23 53 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;