PDO延续查询mysql出现找不到execute()函数
程序员文章站
2024-02-13 08:29:40
...
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
$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
相关文章
相关视频