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