Xây dựng function execute 9.5 (ok)

    public function execute($sql) {
      if (!function_exists('getMicrotime')) {
        function getMicrotime() {
          list($usec, $sec) = explode(" ", microtime());
          return ((float) $usec + (float) $sec);
        }
      }
      $t              = getMicrotime();
      $this->_result  = $this->_execute($sql);
      $this->affected = $this->lastAffected();
      $this->took     = round((getMicrotime() - $t) * 1000, 0);
      $this->error    = $this->lastError();
      $this->numRows  = $this->lastNumRows($this->_result);
      return $this->_result;
    }
    public function _execute($sql) {
      return mysqli_query($this->connection, $sql);
    }
    public function lastAffected($source = null) {
      if ($this->_result) {
        return mysqli_affected_rows($this->connection);
      }
      return null;
    }
    public function lastError() {
      if (mysqli_errno($this->connection)) {
        return mysqli_errno($this->connection) . ': ' . mysqli_error($this->connection);
      }
      return null;
    }
    function lastNumRows($source = null) {
	    if ($this->_result and is_object($this->_result)) {
	      return @mysqli_num_rows($this->_result);
	    }
	    return null;
	  }

Last updated