问题使用PHP连接到远程MySQL数据库 [英] problem connecting to remote mysql database using php

查看:205
本文介绍了问题使用PHP连接到远程MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打开一个cmd外壳和运行

 >的MySQL主机= 12.34.56.78 --port = 1234 --user = myuser的--password =输入mypassword MYDB

我可以成功连接到远程MySQL数据库。

但是,如果我上载我的本地创建一个PHP页面

 < PHP
$主机=12.34.56.78:1234;
$用户名=myuser的;
$密码=输入mypassword;
$ DBNAME =MYDB;
$连接= mysql_connect($主机名,用户名$,$密码)或死亡(错误:无法连接到数据库);
?>

我收到以下错误:

 错误:无法连接到数据库

任何人能解释什么可能会在这里引起的问题?

  mysql_error()=> mysqlnd无法连接到MySQL 4.1+使用旧的认证


解决方案

验证问题是一个已知的问题与PHP 5.3及以上版本的MySQL。检查:

<一个href=\"http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx\" rel=\"nofollow\">http://www.bitshop.com/Blogs/tabid/95/EntryId/67/PHP-mysqlnd-cannot-connect-to-MySQL-4-1-using-old-authentication.aspx

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

解决方案

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

这篇关于问题使用PHP连接到远程MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆