Home > Backend Development > PHP Tutorial > PDO延续查询mysql出现找不到execute()函数

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

WBOY
Release: 2016-06-13 13:11:17
Original
877 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template