你好,请你帮我解决这个错误吗?我是初学者在PHP :)解析错误:语法错误,意外'catch'(Tlve this err_CATCH)on line 41
protected function RunQuery($sql) {
$pdo = $this->conn;
$stmt = $pdo->prepare($sql);
if($stmt) {
$stmt->execute($sql);
} else {
print_r("Unable to prepare the query");
}
catch(PDOException $e) {
print_r($e);
exit(0);
}
}
就像错误状态,你有一个意想不到的'catch'语句。那为什么那个陈述? – David
'catch'总是与'try'一起使用,语法为'try {/ * code * /} catch(Exception $ e){/ * code * /}'。请参阅http://php.net/manual/fr/language.exceptions.php – Kaddath