Home >Backend Development >PHP Tutorial >php数据库操作Call to a member function Execute() on a non-obje报错
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 $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
print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);
print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);
print_r($conn);
$sth = $conn->prepare($sql);
print_r($sth);