$dbh = new PDO($dns, $userId, $password);
$query = 'select customername from customers where cusstomername like :name';
try {
$sth = $dbh->prepare($query);
$sth->execute(array(':name' => 'a%'));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
printf('customername : %s<br/>', $row['customername']);
}
} catch (PDOException $exc) {
echo 'error';
}
沒有這個cusstomername、但是抓不到錯誤
$dbh = new PDO($dns, $userId, $password);
$query = 'select customername from customers where cusstomername like :name';
try {
$sth = $dbh->prepare($query);
if ($sth->execute(array(':name' => 'a%'))) {
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
printf('customername : %s<br/>', $row['customername']);
}
} else {
$stherr = $sth->errorInfo();
echo $stherr[2];
}
} catch (PDOException $exc) {
echo 'error';
}
這樣才有錯誤"Unknown column 'cusstomername' in 'where clause'"
沒有留言:
張貼留言