[PDO]⑦--query()方法执行查询语句

$pdo->query($sql)

3;";
    $stmt = $pdo->query($sql);
    var_dump($stmt);
    /*
     * object(PDOStatement)[2]
  public 'queryString' => string 'select * from user where id>3;' (length=30)
     *如果错的返回false
    */
    echo "
"; foreach ($stmt as $row) { //var_dump($row); echo "编号:" . $row['id'] . "
"; echo "用户名:" . $row['username'] . "
"; echo "邮箱:" . $row['email'] . "
"; echo "
"; } } catch (PDOException $e) { echo $e->getMessage(); } ?>
[PDO]⑦--query()方法执行查询语句_第1张图片
Paste_Image.png

添加

query($sql);
    $stmt = $pdo->query($sql);
    var_dump($stmt);//boolean false

} catch (PDOException $e) {
    echo $e->getMessage();
}
?>

你可能感兴趣的:([PDO]⑦--query()方法执行查询语句)