moxie
2017-03-27 15:11
<?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]
我才刚学不久,我想应该是前面dbname=article库没选错的话,那么SELECT * from article中article不能写数据库,应该改为article库下的某张数据表
PDO—数据库抽象层
30043 学习 · 396 问题
相似问题