duanboshi1472 2014-11-03 11:15
浏览 121
已采纳

解析错误:语法错误,意外T_ELSE,期望第54行/home/petit/public_html/system/database/mysqli.php中的T_FUNCTION

I have made an opencart transfer from a server to another and i am getting the following error Parse error: syntax error, unexpected T_ELSE, expecting T_FUNCTION in /home/petit/public_html/system/database/mysqli.php on line 54

when i try to access my site or my administrator page. Any idea why this is happening? I have followed the procedure step by step.

This is mysqli.php

 <?php
final class MySQLi {
    private $mysqli;

    public function __construct($hostname, $username, $password, $database) {
        $this->mysqli = new mysqli($hostname, $username, $password, $database);

        if ($this->mysqli->connect_error) {
            trigger_error('Error: Could not make a database link (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
        }

        $this->mysqli->query("SET NAMES 'utf8'");
        $this->mysqli->query("SET CHARACTER SET utf8");
        $this->mysqli->query("SET CHARACTER_SET_CONNECTION=utf8");
        $this->mysqli->query("SET SQL_MODE = ''");
    }

    public function query($sql) {
        $result = $this->mysqli->query($sql);



        if ($this->mysqli->errno) {
        //$mysqli->errno
        }

            if (is_resource($resource)) {
                $i = 0;

                $data = array();

                while ($row = $result->fetch_object()) {
                    $data[$i] = $row;

                    $i++;
                }

                $result->close();

                $query = new stdClass();
                $query->row = isset($data[0]) ? $data[0] : array();
                $query->rows = $data;
                $query->num_rows = $result->num_rows;

                unset($data);




                return $query;  
            } else {
                return true;
            }
        } else {
            trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
            exit();
        }
    }

    public function escape($value) {
        return $this->mysqli->real_escape_string($value);
    }

    public function countAffected() {
        return $this->mysqli->affected_rows;
    }

    public function getLastId() {
        return $this->mysqli->insert_id;
    }   

    public function __destruct() {
        $this->mysqli->close();
    }
}
?>

Thank you in advance

  • 写回答

1条回答 默认 最新

  • drf65218 2014-11-03 11:18
    关注

    there is else without if. the if block is closed. do it like -

    if ($this->mysqli->errno) {
    //$mysqli->errno
    
        if (is_resource($resource)) {
            $i = 0;
    
            $data = array();
    
            while ($row = $result->fetch_object()) {
                $data[$i] = $row;
    
                $i++;
            }
    
            $result->close();
    
            $query = new stdClass();
            $query->row = isset($data[0]) ? $data[0] : array();
            $query->rows = $data;
            $query->num_rows = $result->num_rows;
    
            unset($data);
    
    
    
    
            return $query;  
        } else {
            return true;
        }
    } else {
        trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配