当前位置:Gxlcms > PHP教程 > php数据库操作CalltoamemberfunctionExecute()onanon-obje报错

php数据库操作CalltoamemberfunctionExecute()onanon-obje报错

时间:2021-07-01 10:21:17 帮助过:31人阅读

class sqlitedb {
//打开sqlite数据库
function conn($dbname) {
$conn = null;
$path ="/etc/ypm/system.cfg";
if(file_exists($path)){
$dbname = str_replace('../', '', $dbname);
$dbname = str_replace('./', '', $dbname);
require_once('pqmdconfig.php');
$key = "dbpath";//verpath
$dbname = getConfig($key,$path).$dbname;
}
$dbPath = 'sqlite:'.$dbname;
try {
$conn = new PDO($dbPath);
//$conn->beginTransaction();
} catch(PDOException $e) {
echo 'Exception is:'.$e->getMessage();
}
return $conn;
}
以上是数据库的链接和查询操作
include "shm_offset.php";
include "sqlite.php";

$obj= new sqlitedb();

if ( isset($_GET['page'])) {//翻页处理

if($conn=$obj->conn('../ypm.db')){

$sql = "select max(id) as total from data_3sec ";
$total = $obj->query($conn,$sql);
$total = $total['0']['total'];
$now=$_GET['page']?$_GET['page']:1;
if($now >=$total){$now = $total;}
if($now <1){$now = 1;}
$list = $now;

$argv = $_GET['argv'];
$argv = explode("|",$argv);
$num = count($argv)-1;

//$sql = "select data,time from data_3sec order by id desc limit ".$list.",1";
$sql = "select data,time,id from data_3sec order by time desc limit 1 offset ".($list-1);
//因为数据量庞大,无法计算总数(卡死),所以改成ID
//dump($sql);
// exit();

$result = $obj->query($conn,$sql);
$data=$result[0]['data'];

// dump($data);
以上是部分查询代码 Call to a member function Execute() on a non-obje 之前是两个数据库是可以运行的,现在改成了一个数据库之后就报这个错误,代码数据库名字方面也该多来了求助各位高手


回复讨论(解决方案)

错误信息指出 Execute 方法不存在,但在你的代码中并未看到在哪里调用了 Execute

错误信息指出 Execute 方法不存在,但在你的代码中并未看到在哪里调用了 Execute



//查询操作
function query($conn,$sql) {
$result = array();
include "shm_offset.php";
if(count($m_fUsys_OffSet)<2){
if(strpos($sql,'and')==false && strpos($sql,'line')!==false){
$sql = str_replace('where','',$sql);
}
$sql = str_replace('line','',$sql);
$sql = str_replace('=0','',$sql);
$sql = str_replace('= 0','',$sql);
}

try {
$sth = $conn->prepare($sql);
$sth->execute();
//获取结果
//var_dump($conn);
$result = $sth->fetchAll();
} catch(PDOException $e) {
echo 'Exception is:'.$e->getMessage();
}
return $result;
}
不好意思忘贴了

print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);

print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);


只显示了$conn的信息竟然是PDO Object ( )这是没实例化成功?

print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);


终于知道问题在哪了有个地方数据库名字没改到,真是谢谢了要不是print()还找不到,公司临时给的任务也没学过php

人气教程排行