doufuxi7093 2010-08-26 14:00
浏览 29
已采纳

用于MySQLi / MSSQL行获取的php DBAL

I'm trying to write a simple, thin and efficient database abstraction layer on top of the PHP MySQLi (procedural) and MSSQL libraries, to be used like this...

while ($a = db::go('db_name')->query('select * from foo')->row()) {
  print_r($a);
}

I have the class written, but am struggling somewhat with how best to loop through the results. The class will only need to handle select queries, and will have to handle some large result sets. Here's a snippet of the ->row() method...

public function row() {
  return $this->{'get'.ucwords($this->details['type']).'Row'}();
}
private function getMysqliRow() {
  return @mysqli_fetch_assoc($this->result);
}
private function getMssqlRow() {
  return @mssql_fetch_assoc($this->result);
}

At the moment, the call is resulting in an infinite loop, and retrieving the same row each time because the internal pointer in the result set isn't incremented in the same way as a while ($a = mssql_data_seek($result)) call would, which makes complete sense (a result set isn't global, you should be able to handle more than one result set at a time!).

So, does anyone know of an elegant and efficient way around this? Or is the only solution to use the data seek functions (mysqli_data_seek() and mssql_data_seek()) and hold a pointer to the current position in the result set? If so, how efficient is this (I will be handling large result sets > 250000)? And how would the while loop handle reaching the end of the result set?

  • 写回答

1条回答 默认 最新

  • duanrang9348 2010-08-26 15:59
    关注

    Ignore this, it was me being silly! I hadn't made the result resource a static member, so it was being re-retrieved on each call. Apologies!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效