基本上,我已经做了很多搜索,仍然没有找到任何解决这个问题。
我正在尝试将我的应用程序连接到由公司运行和托管的数据库,在外部服务器上(我们已经将此数据库用于我们在用户计算机上运行的应用程序)
我想查询数据库登录,以便当用户在我的应用程序上输入他的用户名和密码时,它会将这些详细信息与数据库中的详细信息进行比较,并回复,说明这些凭据是否正确,并允许用户看到不同的页面,这将从该用户的数据库中提取特定的详细信息(但这是我需要在未来解决的问题)
目前我的主要问题是,我似乎无法让应用程序能够连接到数据库,目前我正在使用WAMP服务器来托管我制作的php文件…
注意:我将使用"user"answers"pass"而不是实际的用户名和密码
<?php
//connecting
//server, username, password, database
$dbhost = 'external ip entered here';
$dbuser = 'user';
$dbpass = 'pass';
$dbdb = 'datbasename';
//connect to mySQL
$connect = mysql_connect ($dbhost,$dbuser,$dbpass) or die("Connection error");
//select the database
mysql_select_db($dbdb) or die ("database selection error");
//Retrieve the login details via POST
$username=$_POST['username'];
$password=$_POST['password'];
//Query the table
$query="SELECT llogint,lpasint FROM TCHAUFF (nolock)
WHERE llogint='$username' AND lpasint='$password'";
//check if there any results returned
$num = mysql_num_rows($query);
//if a record was found matching the details entered in the query
if($num == 1){
//create a while loop that places the returned data into an array
while($list=mysql_fetch_assoc($query)){
//store the returned data into variable
$output = $list;
//encode the returned data in JSON format
echo json_encode( $output );
//close the connection
mysql_close();
}}
?>
我不认为他们的php文件有任何问题,但请纠正我,如果有的话,哈哈!我遇到的问题是,如果我尝试运行这个php文件从WAMP通过将文件放入www文件夹,并去localhost/androidtest.php
我得到一个错误说警告:mysql_connect(): No connection could make because目标机器主动拒绝它
我已经尝试了我能找到的每一个解决方案,
将此信息添加到config.inc.php文件
/* Server: UserSeaCogi[1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'external database';
$cfg['Servers'][$i]['host'] = 'external ip entered here';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'user';
$cfg['Servers'][$i]['password'] = 'pass';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
我想不出好主意!
我已经添加Bind-address = 0.0.0.0到my.ini文件
但我认为这与我设置WAMP的方式有关,但我似乎找不到要改变的地方。
我也知道我绝对可以访问数据库,因为我可以从它运行查询,如果我把它添加到visual studio…需要注意的是,这是2003年的服务器…我知道visual studio有一定的局限性,不确定android的情况如何?
Thanks in advance
在你的php代码
mysql_select_db($dbdb)
应为
mysql_select_db($dbdb,$connect) ;
然后添加以下行
$result = mysql_query($query, $connect);
$num = mysql_num_rows($result);