DbServer::onTask PHP Method

onTask() public method

public onTask ( $serv, $task_id, $from_id, $sql )
    public function onTask($serv, $task_id, $from_id, $sql)
    {
        if (!self::$link) {
            self::$link = new mysqli();
            self::$link->connect($this->config['host'], $this->config['user'], $this->config['pwd'], $this->config['name']);
            //设置数据库编码
            self::$link->query("SET NAMES '" . $this->config['charset'] . "'");
        }
        for ($i = 0; $i < 2; $i++) {
            $result = self::$link->query($sql);
            if ($result === false) {
                if (self::$link->errno == 2013 or self::$link->errno == 2006) {
                    self::$link->close();
                    $r = self::$link->connect();
                    //设置数据库编码
                    self::$link->query("SET NAMES '" . $this->config['charset'] . "'");
                    if ($r === true) {
                        continue;
                    }
                }
            }
            break;
        }
        //var_dump($sql);
        //print_r(self::$link);
        if (is_object($result)) {
            $data = $result->fetch_all(MYSQLI_ASSOC);
            mysqli_free_result($result);
        } else {
            $data = $result;
        }
        return $data;
    }