代码如下
安卓端
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(){
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(){
@Override
public void run()
{
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair(“name”,”SUCCESS”));
params.add(new BasicNameValuePair(“age”,”666666″));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(“http://192.168.210.51/login.php”);
httppost.setEntity(new UrlEncodedFormEntity(params));
httpclient.execute(httppost);
} catch (Exception e) {
Log.i(“eeeeee”, “eeeeeeerrrrrrrrrr”);
}
}
}.start();
}
}
php端
<?php
echo “Hello World!”;
$serverName = “192.168.208.42”;
$uid = “sa”;
$pwd = “sadell”;
$database = “my_db”;
$connectionInfo = array(“PWD”=>$pwd,”UID”=>$uid,”Database”=>$database);
$con = sqlsrv_connect($serverName,$connectionInfo);
if (!$con)
{
echo “FAIL<br/>”;
die(print_r( sqlsrv_errors(),true));
}
else{echo “success”;}
$sql=”INSERT INTO Test(name, age)VALUES (“$_POST[name]”,”$_POST[age]”)”;
$query=sqlsrv_query($con,$sql);
?>
安卓端
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(){
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(){
@Override
public void run()
{
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair(“name”,”SUCCESS”));
params.add(new BasicNameValuePair(“age”,”666666″));
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(“http://192.168.210.51/login.php”);
httppost.setEntity(new UrlEncodedFormEntity(params));
httpclient.execute(httppost);
} catch (Exception e) {
Log.i(“eeeeee”, “eeeeeeerrrrrrrrrr”);
}
}
}.start();
}
}
php端
<?php
echo “Hello World!”;
$serverName = “192.168.208.42”;
$uid = “sa”;
$pwd = “sadell”;
$database = “my_db”;
$connectionInfo = array(“PWD”=>$pwd,”UID”=>$uid,”Database”=>$database);
$con = sqlsrv_connect($serverName,$connectionInfo);
if (!$con)
{
echo “FAIL<br/>”;
die(print_r( sqlsrv_errors(),true));
}
else{echo “success”;}
$sql=”INSERT INTO Test(name, age)VALUES (“$_POST[name]”,”$_POST[age]”)”;
$query=sqlsrv_query($con,$sql);
?>
解决方案
20
可以打trace么
20
用volley试一试