显示连接数据库成功,但是查询不到东西
<?php
//连库
require_once('config.php');
try{
//$pdo=new PDO(":/Applications/MAMP/tmp/mysql/mysql.sock;dbname=article","xrg","happy1227");
$pdo=new PDO('mysql:host=localhost;port:8889;dbname=article','xrg','happy1227');
echo 'success'.'<br/>';
var_dump($pdo);
$state=$pdo->query('SELECT * from article');
foreach($state as $row) {
print_r($row);
}
/* 删除 article 数据表中满足条件的所有行 */
//$count = $pdo->exec("DELETE FROM article WHERE title = 'book'");
/* 返回被删除的行数 */
//print("Deleted $count rows.\n");
}catch(PDOException $e){
echo "connection failed:".$e->getMessage();
}
?>
页面显示
success
/Applications/MAMP/htdocs/article/connect_pdo.php:8:
object(PDO)[1]