使用PDO准备的语句不起作用

时间:2015-03-03 21:27:08

标签: php mysql pdo

我做了一些研究,我发现了两种从PDO对象准备语句的方法。但似乎两者都不起作用。我错过了什么?

命名占位符

$email = 'my_email';
$code = 'my_private_code';
$pdo = new PDO('mysql:host=personal_info;dbname=personal_info', 'personal_info', 'personal_info');
$sql = "UPDATE `promo` SET code = :code WHERE email = :email";
$st = $pdo->prepare($sql);
$st->execute(array(
   ':code' => $code,
   ':email' => $email
));

已停用的占位符

  $pdo = new PDO('mysql:host=personal_info;dbname=personal_info', 'personal_info', 'personal_info');
  $st = $pdo->prepare("INSERT INTO promo (`email`, `code`) VALUES (?, ?)");
  $st->bindParam(1, $email);
  $st->bindParam(2, $code);
  $email = 'my_email@hotmail.com';
  $code = 'my_private_code';
  $st->execute();

0 个答案:

没有答案