首頁 >後端開發 >php教程 > PDO延续查询mysql出现找不到execute()函数

PDO延续查询mysql出现找不到execute()函数

WBOY
WBOY原創
2016-06-13 13:11:17897瀏覽

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn