我试过这个但是没有用
<?php
$db = new PDO('mysql:host=localhost;dbname=localhost;charset=utf8', 'root', '');
function getUser($db) {
$sql = 'SELECT * FROM `user` LIMIT 100';
foreach ($db->query($sql) as $row) {
echo "id".$row['id'] . "\t";
echo "Name".$row['name'] . "\t";
}
}
?>
任何人都可以帮助我吗
答案 0 :(得分:0)
问题在于连接字符串:
$ db = new PDO('mysql:host = localhost; dbname = localhost; charset = utf8','root','');
您使用dbname作为localhost吗? 它应该是dbname = db;
由于