SELECT WHERE语句

时间:2017-12-04 23:06:53

标签: php ionic-framework

我正在尝试从数据库中选择一个值,例如

 $stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = (the most recent value entered ');

我试过了:

$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = "26" '); 

它成功了。无论什么时候我尝试这样的事情:

$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = :acc_id');

$stmt = $pdo->query('SELECT acc_id FROM account_info WHERE acc_id = $acc_id ');

我收到以下错误:

core.js:1350 ERROR SyntaxError: Unexpected token S in JSON at position 0
at JSON.parse (<anonymous>)

我的TS代码:

load()
{
this.http.get('http://localhost:10080/ionic/patients.php')
  .map(res => res.json())
  .subscribe(data =>
  {
     this.items = data;
  });
 }

  viewEntry(param)
{
 this.navCtrl.push('AccInfoPage',param);
}

这是我的HTML:

<ion-item *ngFor="let item of items">
<h2>{{ item.acc_id }} </h2>
<button ion-button color="primary" item-right (click)="viewEntry({ account: item })">View</button>
 </ion-item>

我做错了什么?我该怎么解决?  提前谢谢!

2 个答案:

答案 0 :(得分:1)

如果要创建和执行预准备语句,则需要先准备查询,绑定参数然后执行。

$stmt = $pdo->prepare('SELECT acc_id FROM account_info WHERE acc_id = :acc_id');
$stmt->execute([':acc_id' => 26]);
$result = $stmt->fetchAll();

答案 1 :(得分:0)

SELECT acc_id FROM account_info ORDER BY acc_id DESC LIMIT 1