Sql查询显示用户

时间:2014-05-24 01:22:52

标签: mysql sql pdo

我试过这个但是没有用

<?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";
  }
 }
?>

任何人都可以帮助我吗

1 个答案:

答案 0 :(得分:0)

问题在于连接字符串:

$ db = new PDO('mysql:host = localhost; dbname = localhost; charset = utf8','root','');

您使用dbname作为localhost吗? 它应该是dbname = db;

由于