是否有一种简单的方法可以显示使用PHP传递到MySQL数据库的SQL查询(而不是查询结果),以查看是否存在任何SQL语法错误?例如,假设我想查询下面的查找用户函数。为此,我必须通过回显来修改三个不同的页面以查看最终的sql查询。有没有更简单的方法来做到这一点。
// PAGE 1 --- used to find a user on a webpage
$users = User::find_user();
// PAGE 2 --- used as a function to find a user on a class page
static public function find_all_userid() {
$sql = "SELECT * FROM user WHERE userid=" . $_SESSION['userid'] . " LIMIT 1";
return static::find_by_sql($sql);
}
// PAGE 3 --- this is in the "database" class
static public function find_by_sql($sql) {
$result = self::$database->query($sql);
if(!$result) {
exit("Database query failed.");
}
$object_array = [];
while($record = $result->fetch_assoc()) {
$object_array[] = static::instantiate($record);
}
$result->free();
return $object_array;
}