PDO::exec() 主要是针对没有结果集合返回的操作,如INSERT、UPDATE等操作
PDO::lastInsertId() 返回上次插入操作,主键列类型是自增的最后的自增ID
PDOStatement::fetch() 是用来获取一条记录
PDOStatement::fetchAll() 是获取所有记录集到一个中
<?php
$pdo=new PDO("mysql:host=localhost;dbname=php100","root","");
$pdo->exec("insert into `php100`(`id`,`name`,`hit`)values(‘‘,‘PHP200‘,‘5‘)");
$pdo->query("select * from `php100` limit 0,2");
$row=$sr->fetchAll();
print_r($row);
?>
实例
<?php
$pdo=new PDO("mysql:host=localhost;dbname=php100","root","");
$pdo->exec("insert into `php100`(`id`,`name`,`hit`)values(‘‘,‘PHP200‘,‘5‘)");
$pdo->query("select * from `php100` limit 0,2");
$row=$sr->fetchAll();
print_r($row);
?>
<?php
$pdo=new PDO("mysql:host=localhost;dbname=php100","root","");
$pdo->exec("insert into `php100`(`id`,`name`,`hit`)values(‘‘,‘PHP200‘,‘5‘)");
$sr=$pdo->query("select * from `php100`");
while($row=$sr->fetch())
print_r ($row);
?>