Pdo executes the fetch query statement, and there is a 500th error. How should I write it?

<?php

try {

    $dbh = new PDO( "mysql:host=47.92.xxx.xxx;dbname=lytest","root","xxxxxxx" );

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//

    echo 1;
    $sql = "SELECT * FROM Persons";
    echo 2;
    $sth = $dbh->prepare( $sql );

    $ret = $sth->execute();
    echo 3;
    $arr1 = $ret->fetchAll(PDO::FETCH_ASSOC);
    echo 4;
    print_r($arr1);
    //echo $ret;

    $dbh = null;

} catch (PDOException $e) {
    echo $e->getMessage();
}catch( Exception $e ){
    echo $e->getMessage();
    //die($e->getMessage());
}

every time you run, you can print out "123", which proves to be
$arr1 = $ret- > fetchAll (PDO::FETCH_ASSOC);
this sentence has an error

I have tried

$arr1 = $ret->fetchAll(PDO::FETCH_ASSOC);
$arr1 = $ret->fetch(PDO::FETCH_ASSOC);
$arr1 = $ret->fetch();

is of no use. I found that there is no difference after looking for some information. How should I write it?

Nov.30,2021

//
    $sql = "SELECT * FROM Persons";
    $ret = $dbh->query($sql);
    $arr1 = $ret->fetchAll(PDO::FETCH_ASSOC);
    print_r($arr1);
  • PDO:There is no active transaction

    error The sentry background sees the error There is no active transaction , which occurs in a update method, roughly function update() { $this->db->beginTrans(); try { dosomething(); $this->db->commitTrans(); ...

    Jan.10,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30717-2bd19.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30717-2bd19.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?