query 运行标准SQL语句,并要求您正确转义所有数据,以避免SQL注入和其他问题。execute运行一个准备好的语句,该语句使您可以绑定参数,以避免需要转义或引用参数。execute如果您多次重复查询,效果也会更好。准备语句的示例:$sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour');$sth->bindParam(':calories', $calories);$sth->bindParam(':colour', $colour);$sth->execute();// $calories or $color do not need to be escaped or quoted since the// data is separated from the query最佳实践是坚持准备好的语句并execute提高安全性。