<?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?