Database pdo connection problem
移动用户-1547390
移动用户-1547390 2020-11-15 18:12:58
0
4
997
<?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.
移动用户-1547390
移动用户-1547390

reply all(4)
行走

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

移动用户-1547390

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template