pdo的数组到字符串转换错误

pgky5nke  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(337)

当我试图运行pdo execute时,我得到了一个数组到字符串的转换错误。

$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
$req = $pdo->prepare('SELECT * FROM `customers`');
$req->execute();
$result = $req->fetchAll();
print $result;

浏览器显示错误“注意:数组到字符串的转换”并且只打印“数组”

nzrxty8p

nzrxty8p1#

$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
$req = $pdo->prepare('SELECT * FROM `customers`');
$req->execute();
$result = $req->fetchAll();

print_r($result); 
var_dump($result);

foreach($result as $key => $value){
    $id = $value['id'];

}

相关问题