<?php try{ $pdo = new PDO("mysql:127.0.0.1:3306;dbname='blogs';charset=utf8mb4",'root',''); echo "pdo连接成功".""; }catch(Exception $e){ echo $e->getMessage(); } $str = $pdo->prepare("SELECT * from user"); foreach ($str as $item){ echo $item; }
shows that the connection is successful, but the result is that the MySQL statement
is directly displayed.
Execute first, then use fetch to get the result set
execute() does not execute?
The current $str is a sql statement object, also called a PDOStatement object, which is a preprocessing object. It has a "queryString" attribute, and the value is your current SQL statement
pdo connection successful object(PDOStatement)#2 (1) { ["queryString"]=> string(18) "SELECT * from user" } This is the result of the operation, please give me the answer