mysql 连接 错误4,MySQL连接失败。无法连接到“ http”上的MySQL服务器(4)

I try to connect my android application using JSON Parser to the web hosting. But whenever I try to connect (even just open using url in the browser) I will get the error message.

$dbHost = 'http://sql4.000webhost.com/localhost';

$dbUser = 'a6410240_cbetTD';

$dbPass = 'xxxxxx';

$dbName = 'a6410240_cbetTD';

$conn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());

mysql_select_db($dbName,$conn);

?>

This is my database.php file. The full error message is

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'http' (4) in /home/a6410240/public_html/database.php on line 8.

I have tried change the $conn but still it didn't worked for me.

Thanks

解决方案

If your database and application is on same server then use "locahost" in $dbhost.

And if your database and application is on different servers then you need to use IP address or hostname in $dbhost and the database user should be added on database server provided with required privileges.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值