任何人都可以解释以下PHP代码?

Ibn*_*eed 0 php mysql

任何人都可以解释以下PHP代码的作用


function query($query_string) 
    {
        if ($query_string == "") {
            return 0;
        }

        if (!$this->connect()) {
            return 0; 
        };

        if ($this->QueryID) {
            $this->free_result();
        }

        if ($this->RecordsPerPage && $this->PageNumber) {
            $query_string .= " LIMIT " . (($this->PageNumber - 1) * $this->RecordsPerPage) . ", " . $this->RecordsPerPage;
            $this->RecordsPerPage = 0;
            $this->PageNumber = 0;
        } else if ($this->RecordsPerPage) {
            $query_string .= " LIMIT " . $this->Offset . ", " . $this->RecordsPerPage;
            $this->Offset = 0;
            $this->RecordsPerPage = 0;
        }

        $this->QueryID = @mysql_query($query_string, $this->LinkID);
        $this->Row   = 0;
        $this->Errno = mysql_errno();
        $this->Error = mysql_error();
        if (!$this->QueryID) {
            $this->halt("Invalid SQL: " . $query_string);
        }

        return $this->QueryID;
    }
Run Code Online (Sandbox Code Playgroud)
function next_record() 
    {
        if (!$this->QueryID) {
            $this->halt("next_record called with no query pending.");
            return 0;
        }

        $this->Record = @mysql_fetch_array($this->QueryID);
        $this->Row   += 1;
        $this->Errno  = mysql_errno();
        $this->Error  = mysql_error();

        $stat = is_array($this->Record);
        if (!$stat && $this->AutoFree) {
            $this->free_result();
        }
        return $stat;
    }
Run Code Online (Sandbox Code Playgroud)

可以用更简单的方式完成上述操作,使用ORM是否明智?

Ros*_*oss 5

第一类方法看起来像执行MySQL查询并为分页添加LIMIT子句.第二个将当前查询移动到下一个记录,同时递增分页计数器.

更详细地说,这是第一个样本:

  • 如果查询为空或数据库连接不存在,请退出该方法.
  • 释放任何现有查询.
  • 如果设置了每页的记录数和页码:
    • 将它们添加到查询的LIMIT子句中.
    • 并将它们重置为0.
  • 否则,如果设置了每页的记录:
    • 将其添加到查询的LIMIT子句中.
    • 并将它们重置为0.
  • 运行查询.
  • 将当前行设置为0.
  • 收集错误.
  • 如果查询失败,则会出现错误.
  • 返回查询.

第二个:

  • 如果未设置查询,则会出现错误.
  • 将行信息作为当前行的数组获取.
  • 增加行号.
  • 抓住任何错误.
  • 如果结果不是数组free/close查询.
  • 否则返回结果集.