1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

prepare関数について

Last updated at Posted at 2020-11-07

##prepareとは?
prepare = SQL文の基本部分が同じで値だけ異なるような場合(例えば同じテーブルに値だけ変えて何回もデータを挿入するような場合)に効率よく行える機能を提供

prepareの他に似たメソッドとしてqueryがあります。
違いは、
query変動値がない場合に使用

$pdo->query('SELECT * FROM user');

prepare変動値がある場合に使用(prepare、bindValue、executeを使う)

// SQL文の実行準備
$stmt = $pdo->prepare("SELECT * FROM user WHERE name=:name");

// 変数の値をバインド
$stmt->bindValue(':name', $name, PDO::PARAM_STR);

// SQL実行
$stmt->execute();

参考元はこちら
(https://blog.senseshare.jp/query-prepare.html#index1)
(https://www.javadrive.jp/php/pdo/index8.html)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?