<?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.天蓬老师2020-11-16 14:42:54
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
移动用户-15473902020-11-15 18:13:50
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