简体   繁体   English

无法访问数据库

[英]can't access the database

I'm building an android application which gets the cellID,mcc,mnc and lac of the tower my phone is connected to.I then want to query a MySQL database, which is on my localhost,by sending the value got from the android application in the WHERE clause in the db query.However when i try to do so through my php script it gives an error..here's a snippet of the code: 我正在构建一个Android应用程序,该应用程序获取手机所连接塔的cellID,mcc,mnc和lac。然后我想通过发送从Android应用程序获取的值来查询位于我的本地主机上的MySQL数据库在db查询中的WHERE子句中。但是,当我尝试通过我的php脚本这样做时,它给出了一个错误..以下是代码片段:

mysql_connect($host,$username,$password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB");
$sql="SELECT * FROM gsm_info WHERE mcc='".$_REQUEST['mcc']."'";
$result=mysql_query($sql);
echo "<table border='1' cellspacing='0' cellpadding='3' >";
echo "<tr> <th>lat</th> <th>lon</th> <th>mcc</th> <th>mnc</th> <th>lac</th> <th>cellid</th> </tr>"; 
while($rows=mysql_fetch_array($result,MYSQL_ASSOC)){
echo "<tr><td>";
echo $rows['lat'];
echo "</td><td>";
echo $rows['lon'];

when i open the browser to run the php file,sfter running the app on my android emulator,it gives an error saying 'undefined index mcc'...hope to get some help 当我打开浏览器运行php文件时,在我的android模拟器上运行该应用程序后,出现错误消息“ undefined index mcc” ...希望获得帮助

Do a var_dump( $_REQUEST ); 做一个var_dump( $_REQUEST ); to see if mcc is actually being passed. 查看是否实际通过了mcc

From description of your error it seems that you are not properly setting your 'mcc' parameter in Android code. 从错误的描述来看,您似乎没有在Android代码中正确设置'mcc'参数。 Check Android code that invokes request or if you are not sure, post it here so that we can see what can be the problem. 检查的Android代码调用请求,或者如果你不知道,它张贴在这里,让我们可以看到有什么可以是问题。

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

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