我发展的地方在我使用外部MS Access数据库(对PC)作为我的Android应用程序数据库的应用程序。我已经做了连接MySQL和MSSQL使用PHP为Android,但我想知道如何我将开始为MS Access数据库。
I am developing an application where in I use External Ms Access Database (on PC) as a database for my android application. I have done connectivity for MySql and MSSql using PHP for Android but I want to know as to how shall I proceed for MS Access Database.
任何教程或片段的欢迎!
Any Tutorials or Snippets are welcome !
1)在Android端做出这样的功能:
1) On the Android Side make a function like this:
public void connect_access_php(String vars)
{
List<NameValuePair> itemstring = new ArrayList<NameValuePair>();
itemstring.add(new BasicNameValuePair("VARIABLE", vars));
HttpClient httpclient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 10000); //Timeout Limit
try
{
HttpPost httppost = new HttpPost("url_of_php_file");
httppost.setEntity(new UrlEncodedFormEntity(itemstring));
HttpResponse response = httpclient.execute(httppost);
InputStream content = response.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s;
while ((s = buffer.readLine()) != null) {
//Handle your Values here
}
}catch (Exception e) {
Toast.makeText(getApplicationContext(),"Connection Problem !", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
2)然后PHP页面上,请访问文件中的连接如下:
2) Then on php page, make the connectivity with access file as follows:
<?php
$variab = $_REQUEST['VARIABLE'];
$conn = new COM("ADODB.Connection") or die("Oops!");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Documents and Settings\xxxx\Desktop\access_file.mdb");
$query = "SELECT * FROM table WHERE (Variable = '".$variab."')";
$data = $conn->Execute($query);
while (!$data->EOF)
{
echo $data ->Fields[0]->value . ":";
//echo $data ->Fields[1]->value . " \n";
$data ->MoveNext();
}
?>
通过这个例子,您可以将变量传递给PHP脚本,因此访问文件CRUD功能。
With this example you can pass variables to php script and hence to access file for CRUD functions.
祝您好运!