【发布时间】:2013-02-21 16:37:06
【问题描述】:
我已尝试使用以下代码。但它不起作用。我有一个临时 sqllite 表,我需要将临时数据库中的所有数据插入远程 mysql 服务器。
var url = "http://bmcagro.com/manoj/insertopinion.php";
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
// this.responseText holds the raw text return of the message (used for JSON)
// this.responseXML holds any returned XML (used for SOAP web services)
// this.responseData holds any returned binary data
Ti.API.debug(this.responseText);
var json = this.responseText;
var response = JSON.parse(json);
if (response.logged == "true") {
var newtoast = Titanium.UI.createNotification({
duration: 1000,
message: "Inserted"
});
newtoast.show();
} else {
var toast = Titanium.UI.createNotification({
duration: 2000,
message: "False"
});
toast.show();
}
},
onerror: function(e) {
Ti.API.debug(e.error);
var toast = Titanium.UI.createNotification({
duration: 2000,
message: "Error in Connection!!"
});
toast.show();
},
timeout:5000 });
xhr.open("POST", url);
xhr.send({names: names});
});
而php代码是
<?php
$con = mysql_connect("MysqlSample.db.8189976.hostedresource.com","MysqlSample","xszZ@123ddlj");
if (!$con) {
echo "Failed to make connection.";
exit;
}
$db = mysql_select_db("MysqlSample",$con);
if (!$db) {
echo "Failed to select db.";
exit;
}
$names = $_POST['names'];
foreach ($names as $name) {
mysql_query("INSERT INTO seekopinion(uid,gid,opiniondescription,date,postedto) VALUES (" + $name.gid + "," + $name.tempid + "," + $name.gid + ",NOW()," + $name.gid + ")");
}
if($query) {
$sql = "SELECT * FROM MysqlSample.seekopinion";
$q= mysql_query($sql);
$row = mysql_fetch_array($q);
$response = array(
'logged' => true,
'seekopinion' => $row['seekopinion']
);
echo json_encode($response);
} else {
$response = array(
'logged' => false,
'message' => 'User with same name exists!!'
);
echo json_encode($response);
}
?>
实际上我是 php 和钛的初学者...任何人请帮助我。
【问题讨论】:
-
那么什么不起作用?您是否尝试过调试您的代码?你有错误吗?
-
我没有收到钛代码错误,但插入不起作用
-
那么你得到了什么 MySQL 错误?您是否进行了任何代码调试以验证查询是否按预期打印?您是否直接针对该数据库运行查询以查看它是否正确插入?您已经发布了两段重要的代码,当然您可以将问题归结为几行有问题的代码。
标签: php mysql sqlite appcelerator-mobile