0

I just want to get the database error of my code and write an error log. but it shows this error message. my codeigniter version is 2.2.3 I user SQL Server as my database. How can I solve this.

Fatal error: Uncaught Error: Call to undefined method CI_DB_sqlsrv_driver::error()

try {


            $this->db->trans_start(FALSE);
            for ($i = 0; $i < 10; $i++) {
                $data['Name'] = $i;
                $this->mfunctions->insert('test1', $data);
            }
            for ($i = 0; $i < 10; $i++) {
                $data['Name2'] = $i;
                $this->mfunctions->insert('test2', $data);
            }

            $this->db->trans_complete();

            if ($this->db->trans_status() === FALSE) {
                throw new Exception($this->db->error());
                echo "Fail";

            } else {
                echo "true";
            }
        } catch (Exception $e) {
            $this->db->trans_rollback();
            log_message('error', sprintf('%s : %s : DB transaction failed. Error no: %s, Error msg:%s, Last query: %s', __CLASS__, __FUNCTION__, $e->getCode(), $e->getMessage(), print_r($this->db->last_query(), TRUE)));
        }
Ed Bangga
  • 12,879
  • 4
  • 16
  • 30

1 Answers1

0

I have tried to run your code with some changes. Added empty data array and updated the mfunctions with db. It will be good to what is mfunctions is. Hope it will help:

    try {
    $this->db->trans_start(FALSE);
    for ($i = 0; $i < 10; $i++) {
        $data = array();
        $data['Name'] = $i;
        $this->db->insert('test1', $data);
    }
    for ($i = 0; $i < 10; $i++) {
        $data = array();
        $data['Name2'] = $i;
        $this->db->insert('test2', $data);
    }
    $this->db->trans_complete();
    if ($this->db->trans_status() === FALSE) {
        throw new Exception($this->db->error());
        echo "Fail";
    } else {
        echo "true";
    }
} catch (Exception $e) {
    $this->db->trans_rollback();
    log_message('error', sprintf('%s : %s : DB transaction failed. Error no: %s, Error msg:%s, Last query: %s', __CLASS__, __FUNCTION__, $e->getCode(), $e->getMessage(), print_r($this->db->last_query(), TRUE)));
}