当我试图运行pdo execute时,我得到了一个数组到字符串的转换错误。
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');$req = $pdo->prepare('SELECT * FROM `customers`');$req->execute();$result = $req->fetchAll();print $result;
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
$req = $pdo->prepare('SELECT * FROM `customers`');
$req->execute();
$result = $req->fetchAll();
print $result;
浏览器显示错误“注意:数组到字符串的转换”并且只打印“数组”
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'];}
print_r($result);
var_dump($result);
foreach($result as $key => $value){
$id = $value['id'];
}
1条答案
按热度按时间nzrxty8p1#