php資料庫操作Call to a member function Execute() on a non-obje報錯

來源:互聯網
上載者:User
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
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.