致命错误:在第30行调用未定义的方法MDB2_Error :: execute()(SQLyog)

时间:2017-04-17 03:36:55

标签: php

我目前正在使用PHP处理仪表板。我需要从SQLyog中的数据库中获取数据,并将其传输到图形中。问题是我一直收到这个错误;致命错误:在类编码中调用第30行的未定义方法MDB2_Error :: execute()。错误发生在$res = $query->execute($data);有人可以帮我编码吗?

以下是课程的代码。

<?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

1 个答案:

答案 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核实。在您的情况下,它是,因此您无法在$res = $query->execute($data);对象上调用MDB2_Error,而这正是错误消息告诉您的内容。

添加if语句以检查$query变量上的错误并检查您收到的错误消息。