简体   繁体   English

使用PHP连接到远程MySQL数据库的问题

[英]problem connecting to remote mysql database using php

If I open up a cmd shell and run 如果我打开一个cmd外壳并运行

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

I can successfully connect to the remote mysql database. 我可以成功连接到远程mysql数据库。

But if I create a php page on my localhost containing 但是,如果我在本地主机上创建一个php页面,

<?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

Auth problems are a known issue with PHP 5.3 and older versions of MySQL. 身份验证问题是PHP 5.3和旧版MySQL的一个已知问题。 Check this: 检查一下:

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

maybe in your php.ini parameter sql.safe_mode is "1"? 也许在您的php.ini参数sql.safe_mode中是“ 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. 有关默认值,请参见相关数据库的连接功能文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM