2
1

More than 5 years have passed since last update.

DBクエリで変数を使用する

Posted at

生のクエリで変数を入力し、$を:に変える。

$query = "SELECT * FROM users WHERE username = :name"; // 実行したいクエリ

execute()を行なう際にbind()で置換してあげる。

// bind the variable and run the query, produces SELECT * FROM users WHERE username = 'John'
$result = DB::query($query)->bind('name', $name)->execute();

Query Builder Select - クラス - FuelPHP ドキュメントより

2
1
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
2
1