日期:2014-05-17  浏览次数:20540 次

PDO连续查询mysql出现找不到execute()函数
$db = new PDO($db_config['dsn'],$db_config['username'],$db_config['password']);//建立连接
$db->exec('SET NAMES '.C('DB_CHARSET'));
$sql = "select * from tab limit 1";
$sth = $db->prepare($sql);
$sth->execute();
$result = $sth->fetch();
print_r($result);//此处数据可以查询出来
$sql = "select * from tab limit 2";
$sth = $db->prepare($sql);
$sth->execute();//程序执行到此处就会报错
$sth->fetchAll();
dump($result);
报错信息:Fatal error: Call to a member function execute() on a non-object in

------解决方案--------------------
php 与pdo 数据库连接实例
http://www.111cn.net/phper/21/pdo_php.htm