0

If I open up a cmd shell and run

>mysql --host=12.34.56.78 --port=1234 --user=myuser --password=mypassword mydb

I can successfully connect to the remote mysql database.

But if I create a php page on my localhost containing

<?php
$hostname = "12.34.56.78:1234";
$username = "myuser";
$password = "mypassword";
$dbname   = "mydb";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
?>

I get the following error:

Error: could not connect to database

Can anyone explain what might be causing the problem here?

mysql_error() => mysqlnd cannot connect to MySQL 4.1+ using old authentication
5
  • 1
    use $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database (".mysql_error()); and give results here Commented Jun 22, 2011 at 19:21
  • 1
    I assume --password=mypasword and $password = "mypassword" is a simple typo, yes? Commented Jun 22, 2011 at 19:22
  • Please enable error reporting and post the error the mysql_connect function gives. Commented Jun 22, 2011 at 19:23
  • Could you output the function mysql_error() in your die()? That would give the reason mysql can't be connected to. Commented Jun 22, 2011 at 19:23
  • dev.mysql.com/doc/refman/5.5/en/old-client.html Commented Jun 22, 2011 at 19:28

2 Answers 2

1

Auth problems are a known issue with PHP 5.3 and older versions of MySQL. Check this:

http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

maybe in your php.ini parameter sql.safe_mode is "1"?

sql.safe_mode boolean 

If turned on, database connect functions that specify default values will use those values in place of supplied arguments. For default values see connect function documentation for the relevant database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.