search

Home  >  Q&A  >  body text

Database pdo connection problem

<?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移动用户-15473901512 days ago1035

reply all(4)I'll reply

  • 行走

    行走2020-11-24 12:29:41

    Execute first, then use fetch to get the result set

    reply
    0
  • 木鸡

    木鸡2020-11-19 06:33:39

    execute() does not execute?

    reply
    0
  • 天蓬老师

    天蓬老师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

    reply
    0
  • 移动用户-1547390

    移动用户-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

    reply
    0
  • Cancelreply