LoginSignup
1
3

More than 5 years have passed since last update.

CakePHP2: queryでプレースホルダ

Posted at

LIKEを使う場合にプレースホルダが効かずに悩んでいました:

ダメな例1:

ng1.php
$sql = "SELECT * FROM shops WHERE name LIKE '%?%'";
$results = $this->query($sql, array('原宿') );

ダメな例2:

ng2.php
$sql = "SELECT * FROM shops WHERE name LIKE %?%";
$results = $this->query($sql, array('原宿') );

正しい書き方:

ok.php
$sql = "SELECT * FROM shops WHERE name LIKE ?";
$results = $this->query($sql, array('原宿') );
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3