PDO——Call to a member function query() on a non-object
程序员文章站
2024-01-14 12:36:16
...
Think PHP在3.2之后好像就不支持PDO扩展了,然后我为了用PDO在控制层中写了一个php文件,里面只是写了实例化PDO的一段代码,我在控制请中引入这个文件,刚开始连接查询数据的时候没有错误,但是好像是有返回值的时候就报了一个——“**Call to a member function query() on a non-object**”的错误,有哪位了解的,请教下
pdo.class.php
true));
?>
CommonController.class.php
public function checkPDO($rolename,$mid=1){
if (intval($mid) > 0) {
require_once('Pdo.class.php');
$res = $PDO->query("SELECT r_id as rid FROM `shop_role` where r_method='$rolename' limit 1");
//
$roleres = $res->fetch(2);
$checkmethID = $roleres['rid'];
// dump($checkmethID);exit;
$res = $PDO->query("SELECT gid FROM `shop_ag_access` where mid='$mid'");
$agres = $res->fetchAll(2);
if($checkmethID){
foreach ($agres as $key => $value) {
$rges = $PDO->query("SELECT rid FROM `shop_rg_access` where gid='".$value['gid']."'");
$rges = $rges->fetchAll(2);
if (!$rges) {
return fasle;
}
$rgarr = array();
foreach ($rges as $kk => $val) {
$rgarr[] = $val['rid'];
}
$agres[$key]['gid'] = $rgarr;
}
$PDO = null;
$arr = array();
foreach ($agres as $key => $value) {
$arr[] = $value['gid'];
}
foreach ($arr as $key => $value) {
if (in_array($checkmethID, $value) == true) {
return true;
}
}
return false;
}else{
return false;
}
}else{
return false;
}
}
上面的代码可以忽略不看,就是Think PHP链接PDO的问题
回复内容:
Think PHP在3.2之后好像就不支持PDO扩展了,然后我为了用PDO在控制层中写了一个php文件,里面只是写了实例化PDO的一段代码,我在控制请中引入这个文件,刚开始连接查询数据的时候没有错误,但是好像是有返回值的时候就报了一个——“**Call to a member function query() on a non-object**”的错误,有哪位了解的,请教下
pdo.class.php
true));
?>
CommonController.class.php
public function checkPDO($rolename,$mid=1){
if (intval($mid) > 0) {
require_once('Pdo.class.php');
$res = $PDO->query("SELECT r_id as rid FROM `shop_role` where r_method='$rolename' limit 1");
//
$roleres = $res->fetch(2);
$checkmethID = $roleres['rid'];
// dump($checkmethID);exit;
$res = $PDO->query("SELECT gid FROM `shop_ag_access` where mid='$mid'");
$agres = $res->fetchAll(2);
if($checkmethID){
foreach ($agres as $key => $value) {
$rges = $PDO->query("SELECT rid FROM `shop_rg_access` where gid='".$value['gid']."'");
$rges = $rges->fetchAll(2);
if (!$rges) {
return fasle;
}
$rgarr = array();
foreach ($rges as $kk => $val) {
$rgarr[] = $val['rid'];
}
$agres[$key]['gid'] = $rgarr;
}
$PDO = null;
$arr = array();
foreach ($agres as $key => $value) {
$arr[] = $value['gid'];
}
foreach ($arr as $key => $value) {
if (in_array($checkmethID, $value) == true) {
return true;
}
}
return false;
}else{
return false;
}
}else{
return false;
}
}
上面的代码可以忽略不看,就是Think PHP链接PDO的问题
“on a non-object”说明你调用了对象不存在的方法,或这个对象没有实例化。检查下代码,留意在调用对象的方法的位置。
试试把query换做exec
推荐阅读
-
PDO——Call to a member function query() on a non-object
-
php中出现“Call to a member function Execute() on a non-object”的有关问题
-
php 连上数据库之后出现Call to undefined function mssql_query()?
-
Fatal error: Call to a member function fpage() on a non-object
-
Fatal error: Call to a member function fpage() on a non-object解决方案
-
Fatal error: Call to a member function get() on a non-object
-
Call to a member function on a non-object,分不够再加
-
PHP对象编程有关问题,Call to a member function hello() on a non-object
-
PHP对象编程有关问题,Call to a member function hello() on a non-object
-
jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...