【发布时间】:2010-09-16 00:41:32
【问题描述】:
过去我会这样做:
$sql = 'SELECT * FROM customers WHERE customer_email="' . mysql_real_escape_string($_POST['customer_email']) . '" ';
$res = mysql_query($sql);
// if there are no hits...
if(mysql_num_rows($res) == FALSE) {
今天我正在做同样的事情,但是使用准备好的语句:
$stmt = $dbh->prepare("SELECT * FROM customers where customer_email = ? LIMIT 1");
if ($stmt->execute(array($_POST['customer_email']))) {
我准备好的语句 if($stmt... 的第二行是“如果这个查询得到一个结果”还是“如果这个查询不管结果如何都被执行,即如果它执行没有错误”。
我要解决的是使用准备好的语句,您如何执行相当于 mysql_num_rows() == FALSE 的操作?
谢谢!!
【问题讨论】:
标签: php mysql pdo prepared-statement