问题描述
我尝试将使用JSON Parser的android应用程序连接到虚拟主机.但是只要我尝试连接(甚至只是使用浏览器中的url打开),我都会收到错误消息.
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.
<?php
$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);
?>
这是我的database.php文件.完整的错误消息是
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.
我曾尝试更改$ conn,但是它对我没有用.
I have tried change the $conn but still it didn't worked for me.
谢谢
推荐答案
如果您的数据库和应用程序位于同一台服务器上,请使用 $中的"locahost" dbhost .
If your database and application is on same server then use "locahost" in $dbhost.
并且如果您的数据库和应用程序位于不同的服务器上,则需要使用 $ dbhost 中的 IP地址或主机名和数据库用户应该添加到具有必需特权的数据库服务器上.
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.
这篇关于MySQL连接失败.无法连接到"http"上的MySQL服务器(4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!