$pdo = new \PDO("mysql:host=127.0.0.1;dbname=tongcheng",'root','qwe123toor'); $pdo -> query('set names utf8'); $ros = $pdo -> query("select * from hotel_base where id < 10"); $rs = $ros -> fetchAll(\PDO::FETCH_ASSOC); foreach ($rs as $key => $value) { echo $value['id'] . '-'.$value['res_name'].'<br>'; } LINUX 主机 如果host=localhost,那遇到了奇怪问题,各种尝试,不解决。 百度了一下,看到有人说,host=127.0.0.1果然解决了。。。。