我正在为Android构建软键盘,它有我想上传到我的数据库中的用户行在我的网站服务器上的设置,然后当用户更改设备和登录,设置是一样的。我曾经与SQL工作,但我没有连接Android应用程序到我的网站数据库的经验。我在网上找到了一些东西,但它给我的字符串示例我的空结果插入我的数据库。这是我的数据库中的表,我想运行测试:
I'm building soft keyboard for android and it has settings that I want to upload to users row in my database on my website server and then when user changes the device and signs in, settings are the same. I have worked with SQL before, but I haven't had an experience with connecting android app to my website database. I have found something online but it gives my null result for string example I inserted in my database. Here is the table in my database that I want to run test on:
name |详情
name | detail
lazar | firstname
lazar | firstname
jelic |姓氏
rocky | balboa
rocky | balboa
我在我的托管网站服务器上有一个名为 keyboard.php 的php脚本, / p>
I have php script on my hosted website server named keyboard.php and this is how it looks:
<?php mysql_connect("hostname", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $link= $_GET['link']; $query = "SELECT * FROM keyboard WHERE link=" . "'" . $link. "'"; $result =mysql_query($query); if($result){ while($row= mysql_fetch_array( $result )) { echo $row['name'] . " " . $row['link'] . " " . $row['time']; } } ?>这是我的 SyncDatabse.java :
public class SyncDatabase { public static String getFromDB(String linkToGetData) throws IOException { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient=new DefaultHttpClient(); HttpGet httpget = new HttpGet("www.ecloga/keyboard.php?link=" + linkToGetData); HttpResponse response = httpclient.execute(httpget); String theResponse = EntityUtils.toString(response.getEntity()); return theResponse; } }请帮助我。提前致谢。问任何你想知道的。
Please help me with this. Thanks in advance. Ask anything you want to know.
推荐答案测试此PHP代码,因为您的结果为空:
Test this php code because your result is empty:
if (isset ($_GET ["name"])){ $name = mysql_real_escape_string($_GET ["name"]); $query = htmlentities ($query); mysql_query("SET NAMES 'utf8'"); $query = mysql_query("SELECT * FROM my_table WHERE name = '$name'); $result = mysql_query($query); $rows = array(); if (!empty($result)){ while($r = mysql_fetch_assoc($result)){ // $rows[] = $r; has the same effect, without the superfluous data attribute $r["Column1"] = $r["Column1"]; $r["Column2"] = $r["Column2"]; //You can add many columns like the table have $rows[] = $r; //$rows[] = array('Deal' => $r); } echo json_encode($rows); } }更多推荐
将Android应用程式资料与网站资料库连结
发布评论