【发布时间】:2015-01-09 23:17:10
【问题描述】:
谁能给我解释一下为什么下面的function1中的prepare语句没有返回结果,但是function2中的查询语句确实返回了结果(12)。
class Test
{ function function1($db)
{
//date_default_timezone_set('America/Chicago'); // CDT
$month = "January"; //date('F');
$day = "9"; //date('j');
// let's query for died today
$stm = $db->prepare("SELECT * FROM graves WHERE dod_month = ? AND dod_day = ? ORDER BY dod_year DESC");
$stm->bindValue(1, $month, PDO::PARAM_STR);
$stm->bindValue(2, $day, PDO::PARAM_STR);
// $stm = $db->query("SELECT * FROM graves WHERE dod_month = 'January' AND dod_day = '9' ORDER BY dod_year DESC");
$affected_rows = $stm->rowCount();
$stm->execute();
var_dump($affected_rows,$month,$day);
}
function function2($db)
{
//date_default_timezone_set('America/Chicago'); // CDT
//$month = "January"; //date('F');
//$day = "9"; //date('j');
// let's query for died today
// $stm = $db->prepare("SELECT * FROM graves WHERE dod_month = ? AND dod_day = ? ORDER BY dod_year DESC");
// $stm->bindValue(1, $month, PDO::PARAM_STR);
//$stm->bindValue(2, $day, PDO::PARAM_STR);
$stm = $db->query("SELECT * FROM graves WHERE dod_month = 'January' AND dod_day = '9' ORDER BY dod_year DESC");
$affected_rows = $stm->rowCount();
$stm->execute();
var_dump($affected_rows);
}
}
var_dump 的结果是:
int 0
字符串“一月”(长度=7)
字符串“9”(长度=1)
int 12
【问题讨论】: