任何人都可以解释下面的PHP代码吗?
问题描述:
谁能解释一下下面的PHP代码确实任何人都可以解释下面的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;
}
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;
}
,在上面的更简单的方式来完成,这将是明智使用ORM?
答
第一类方法看起来像执行MySQL查询并添加分页的LIMIT子句。第二个将当前查询移动到下一个记录上,同时递增分页计数器。
详细地说,这里的第一个样本:
- 退出方法,如果查询为空或数据库连接不存在。
- 释放任何现有的查询。
- 如果每页和页码的记录数设置:
- 将它们添加到查询的LIMIT子句。
- 而且他们重置为0
- 否则,如果每页记录设置:
- 它添加到查询的LIMIT子句。
- 并将它们重置为0.
- 运行查询。
- 将当前行设置为0.
- 收集错误。
- 如果查询失败并出现错误。
- 返回查询。
而第二个:
- 如果查询未设置停止与错误。
- 将行信息作为当前行的数组获取。
- 递增行号。
- 捕获任何错误。
- 如果结果不是数组空闲/关闭查询。
- 否则返回结果集。
答
是的,你是对的罗斯它像一个类中的分页函数,它逐个调用记录。
我建议你搜索另一个数据库访问类而不是这个,如果你可以... – 2009-07-13 19:10:17
你可以详细说明,你想让我使用PDO吗? – 2009-07-14 07:19:54