2017-04-17 28 views
1

我目前正在使用PHP在儀表板上工作。我需要從SQLyog中的數據庫中獲取數據,並將其轉換爲圖形。問題是我不斷收到這個錯誤;致命錯誤:在類編碼的第30行調用未定義的方法MDB2_Error :: execute()。錯誤是在$res = $query->execute($data);有人可以幫我編碼嗎?致命錯誤:調用第30行(SQLyog)上的未定義方法MDB2_Error :: execute()

這裏是類的代碼。

<?php 
class fetch_ranking extends MDB2{ 
    var $con; 
    var $tbl_user; 
    var $tbl_isi_scopus_webo; 

    function fetch_ranking ($dsn) { 
     $this->con =& MDB2::singleton($dsn, $options=null); 
     //echo $this->con->getMessage(); 
     if (PEAR::isError($this->con)) { 
      die($this->con->getMessage()); 
     } 

     $this->tbl_user = 'user'; 
     $this->tbl_isi_scopus_webo = 'ISI_SCOPUS_WEBO'; 
    } 

    function fetch_webojuly16(){ 

     $types = array(); 
     $sql = "select university, criteria_rank as presence 
       from isi_scopus_webo 
       where month='july' 
       and year='2016' 
       group by university" ; 

     $query = $this->con->prepare($sql,$types,MDB2_PREPARE_RESULT); 
     $data = array(); 
     $res = $query->execute($data); 

     if (PEAR::isError($res)) { 
      die($res->getMessage());   
     } 

     $this->con->setFetchMode(MDB2_FETCHMODE_ASSOC); 
     $valrec = $res->fetchAll(); 
     return $valrec; 
    } 
}?> 

這是圖表。

<?php 
require_once($_SERVER['DOCUMENT_ROOT'].'/config/siteconf.php'); 
require_once($basehome.'/config/default.php'); 
require_once($basedir.'/mod/ppsg/dsn.php'); 
require_once($basehome.'/mod/ppsg/class/fetch_data_from_db_isi_scopus_webo.php'); 

$current_year = date('Y', strtotime(date('Y'))); 

//$fhObj = new fetch_ranking($ranking); 

$hostname="192.168.111.55"; 
$username="devopt"; 
$password="G0devopt$"; 
$dbname="ranking"; 


//Connect to the database 
$connection = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL"); 
echo "Connected to MySQL<br>"; 


mysql_select_db($dbname, $connection) 
    or die("Could not select examples"); 

$xdata=array(); 
$ydata=array(); 

$xdata['name'] = 'PRESENCE'; 
$ydata['name'] = 'UNIVERSITY'; 

$ydata['color'] = '#ABEBC6'; 

//Call to a member function fetch_webojuly16() on a non-object 
$webojuly16 = $fhObj->fetch_webojuly16(); 

foreach($webojuly16 as $wj16){ 
    $xdata['data'][] = $wj16['presence']; 
    $ydata['data'][] = $wj16['university']; 
} 

$json_arr = array($xdata,$ydata); 
print json_encode($json_arr, JSON_NUMERIC_CHECK); 

?> 

This is the coding for graph

+0

哪一行導致錯誤? –

+0

第35行。關於圖表代碼 – Anis

+0

您應該粘貼所有代碼,而不是發佈屏幕截圖。 –

回答

0

$this->con->prepare($sql,$types,MDB2_PREPARE_RESULT);調用可能的情況下,返回MDB2_Error對象prepare()語句失敗,對http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodprepare作爲記錄。如果情況確實如此,您必須查詢PEAR::isError。在你的情況下,所以你不能在MDB2_Error對象上調用$res = $query->execute($data);,而這正是錯誤信息告訴你的。

添加if語句以檢查$query變量上的錯誤並檢查獲得的錯誤消息。

相關問題