我为 android 设备编写了一个程序,它将呼叫日志发送到我主机中的数据库。我使用httpPost
方法来做到这一点,另一方面我有一个 php 代码。
当我尝试在请求中运行此代码时,我得到一个页面,主要是我看到这个:
500 Internal Server Error
我给出了Apache Error Log
这个错误:
PHP Startup: Suhosin Extension does not officially support PHP 5.2 and below anymore, because it is discontinued. Use it at your own risk. in Unknown on line 0
我的主机提供商不允许我直接更改php.ini
文件。
我的一些 php 代码方面:
function callLogSyncToCount()
{
global $serverAddress, $DBusername, $DBpassword, $DBname;
$userID = $_POST['userID'];
$data = $_POST['data'];
$logs = explode('`second`', $data);
foreach($logs as $item)
{
//list($number, $duration, $date, $type) = explode("`first`", $item);
$counter = 0;
$con = mysql_connect($serverAddress, $DBusername, $DBpassword) or die (mysql_error());
if (!$con)
{
die('Could not connect: ' . mysql_error());
return false;
}
mysql_select_db($DBname, $con);mysql_query("SET NAMES 'utf8'");
$result = mysql_query("SELECT * FROM `call_log` WHERE `user_id` = '".$userID."' AND `number` = '".$number."' AND `date` = '".$date."' AND `type` = '".$type."'") or die (mysql_error());
while($row = mysql_fetch_array($result))
{
$counter++;
}
if ($counter < 1)
{
mysql_query("INSERT INTO `call_log`(`user_id`, `date`, `duration`, `number`, `type`) VALUES ('".$userID."', '".$date."', '".$duration."', '".$number."', '".$type."')") or die (mysql_error());
}
mysql_close($con) or die (mysql_error());
}
return true;
}
我的一些安卓端代码是:
private class SyncToCount extends AsyncTask<String, Void, String> {
@SuppressLint("SimpleDateFormat")
@Override
protected String doInBackground(String... param) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(param[0]);
SimpleDateFormat mySQLFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mySQLFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
long ID = Long.parseLong(param[1]);
List<callLogType> calls = new ArrayList<CallLogUtility.callLogType>();
calls = getCallList();
String sendStr = "";
globalVars.syncLogSize = calls.size();
try {
int j = 0;
for(int i = 0; i < calls.size() && j < 20; i++)
{
if(calls.get(i).ID <= ID)
continue;
j++;
sendStr += calls.get(i).PhoneNumber + "`first`";
sendStr +=Integer.toString(calls.get(i).Duration)+ "`first`";
Date newDate = new SimpleDateFormat("d MMM yyyy hh:mm:ss z").parse(calls.get(i).Date);
sendStr +=mySQLFormat.format((newDate))+ "`first`";
sendStr +=Integer.toString(calls.get(i).Type)+ "`second`";
globalVars.syncLogUntil+=1;
}
} catch (Exception e) {
}
try
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("syncType", "calllogtocount"));
nameValuePairs.add(new BasicNameValuePair("userID", param[1]));
nameValuePairs.add(new BasicNameValuePair("data", sendStr));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
@SuppressWarnings("unused")
HttpResponse response = httpclient.execute(httppost);
BufferedReader in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
}
catch(Exception ex)
{
}
return null;
}
}
这段代码不起作用,但我的登录代码在这样的语法下以及从这个android代码和那个服务器以及php和数据库中都能正常工作。
帮帮我,我对php和android模棱两可...