0
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?

PHPのプレースホルダとは

Posted at

目的

phpで使うブレースホルダが良くわからなかったのでまとめた

ブレースホルダとは

SQL文の中にPHPの変数を直接書くと、悪意のあるユーザーからdbを操作される可能性がある。

ダメな例
$sql = "SELECT * FROM user WHERE name= '$name'";

プレースホルダを使用する

$sql = "SELECT * FROM user WHERE name= :name";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$bands = $stmt->fetchAll(PDO::FETCH_ASSOC);//表示

$parmsは事前に

$parms = [];

で定義すると空でも使える。

参考サイト

0
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
0
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?