作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 php 脚本中我这样做:
$q=mysql_query($_REQUEST['query']);
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
在android中我想执行这个:
nameValuePairs.add(new BasicNameValuePair("query", "SELECT name FROM RecOrg_Univ WHERE city='Rome'"));
我哪里错了?
如果我将整个 SELECT... 放入 php 脚本中,并且我只发送属性“Rome”它会起作用,否则不会... :( 但我需要发送整个 SELECT......
最佳答案
PDO 准备示例,以保护您免受注入(inject)。
来自:[andriod] nameValuePairs.add(new BasicNameValuePair("city", "Rome"));
接收脚本:
<?php
$hostname = 'localhost';
$username = 'username';
$password = 'password';
if(isset($_REQUEST['city'])){
$city=$_REQUEST['city'];
}else{
die('Missing Something...');
}
$dbh = new PDO("mysql:host=$hostname;dbname=YOURDB", $username, $password);
/*** The SQL SELECT statement ***/
$stmt = $dbh->prepare("SELECT name FROM RecOrg_Univ WHERE city=:city");
$stmt->bindParam(':city', $city);
/**Execute it**/
$stmt->execute();
/*** fetch the results ***/
$result = $stmt->fetchAll();
/*** loop of the results and hold in an array then echo***/
foreach($result as $row)
{
$output[]=$row['name'];
}
echo json_encode($output);
/*** close the database connection ***/
$dbh = null;
?>
关于php - 从android到php再到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7211205/
我有本地更改和远程更改。 有人告诉我必须先推,再 pull 。这背后有什么原因吗? 最佳答案 那个人错了:正确的模型是pull-before-you-push,而不是相反。 当您pull时,git 将
我正在使用最新版本的 Flat UI Pro 1.3.2 ( http://designmodo.com/flat/ ),jQuery 插件 flatui-radiocheck v0.1.0 和 iO
我是一名优秀的程序员,十分优秀!