将Android应用程式资料与网站资料库连结

编程入门 行业动态 更新时间:2024-10-18 22:35:52
本文介绍了将Android应用程式资料与网站资料库连结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为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应用程式资料与网站资料库连结

本文发布于:2023-10-24 14:11:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程式   资料库   资料   网站   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!