Link to home
Start Free TrialLog in
Avatar of jimbona27
jimbona27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

php help with mysql_connect

Hi ee,
I have this line of code to connect to a remote database but I get the following error:


Warning: mysql_connect() [function.mysql-connect]: OK packet 6 bytes shorter than expected in C:\wamp\www\conn.php on line 15

Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using old authentication in C:\wamp\www\conn.php on line 15
Could not connect: mysqlnd cannot connect to MySQL 4.1+ using old authentication


can someone please advise how I can resolve this issue?
Thanks,
$con = mysql_connect('x.x.x.x', $strDatabaseUser, $strDatabasePassword);

Open in new window

Avatar of Gregory_V
Gregory_V
Flag of United States of America image

Create a new user ID and password for the database and retry.
Avatar of jimbona27

ASKER

can you show me how to do that as I only have dbforge to manipulate the database.  im used to phpmyadmin and ms sql studio..???

thanks,
i've tried this:

grant usage on database_name.* to user_name@localhost IDENTIFIED BY ’somepassword’ WITH GRANT OPTION;

and not I get
Access denied for user 'name@x.x.x.x' (using password: YES) 

Open in new window

i've noticed the IP address stated in the error is different to the IP I set within the mysql_connect command.

please note: I am behind a VPN client although this is running and DBForge can connect to the IP address im using in the connect command..
Hmm, DBForge will have a security manager that will give you user names and access rights for each database.

its empty...?
any ideas?
gtrab.GIF
SOLUTION
Avatar of Gregory_V
Gregory_V
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i've spoken to the people that host the database and they are using PHP 5.1 whereas we are using 5.3

any suggestions?  can I use a different method to connect or something?
Thanks,

this is the error:


Warning: mysql_connect() [function.mysql-connect]: OK packet 6 bytes shorter than expected in C:\wamp\www\try.php on line 10

Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using old authentication in C:\wamp\www\try.php on line 10
Unable to select database
<?php

class DB {	
	var $conn;

	function __construct() {
		$user = "xxx";
		$password = "xxx";
		$db = "xxx";
		$this->conn = mysql_connect('xxx', $user, $password);
		@mysql_select_db($db) or die("Unable to select database");
	}		
	
	function getConn() {
		return $this->conn;
	}
}

$db = new DB();
;?>

Open in new window

i've tested the code on the actual server and it works but for me using WAMP (which is PHP 5.3) it fails..

Avatar of Shinesh Premrajan
This is generally a fairly simple problem, the password in the database is using the older short hash method instead of the newer method.

To fix these reset the password
SET PASSWORD FOR 'user'@'localhost' = PASSWORD(newpassword');

This is what actually causing you this problem:
http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehul_Panchal
Mehul_Panchal

i think you r using old version

Thanks
Mehul Panchal