From 030232dfc32c6464c7180a89822b2b57f1bd8868 Mon Sep 17 00:00:00 2001 From: mdean Date: Sun, 1 Jul 2001 16:55:07 +0000 Subject: [PATCH] Added limit_query function. --- phpgwapi/inc/class.db_mysql.inc.php | 49 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/phpgwapi/inc/class.db_mysql.inc.php b/phpgwapi/inc/class.db_mysql.inc.php index d3a150eee5..8903edf12a 100644 --- a/phpgwapi/inc/class.db_mysql.inc.php +++ b/phpgwapi/inc/class.db_mysql.inc.php @@ -23,6 +23,7 @@ class db { var $Password = ""; /* public: configuration parameters */ + var $use_pconnect = True; var $auto_stripslashes = False; var $Auto_Free = 0; ## Set to 1 for automatic mysql_free_result() var $Debug = 0; ## Set to 1 for debugging messages. @@ -74,10 +75,16 @@ class db { $Password = $this->Password; /* establish connection, select database */ - if ( 0 == $this->Link_ID ) { - $this->Link_ID=mysql_pconnect($Host, $User, $Password); - if (!$this->Link_ID) { - $this->halt("pconnect($Host, $User, \$Password) failed."); + if ( 0 == $this->Link_ID ) + { + if ($this->use_pconnect) + $this->Link_ID=mysql_pconnect($Host, $User, $Password); + else + $this->Link_ID=mysql_connect($Host, $User, $Password); + + if (!$this->Link_ID) + { + $this->halt("connect($Host, $User, \$Password) failed."); return 0; } @@ -158,6 +165,38 @@ class db { return $this->Query_ID; } + // public: perform a query with limited result set + function limit_query($Query_String, $offset, $num_rows, $line = '', $file = '') + { + global $phpgw_info; + + if ($Query_String == '') + return 0; + + if (!$this->connect()) + return 0; // we already complained in connect() about that. + + if ($this->Query_ID) + $this->free(); + + if ($this->Debug) + printf("Debug: limit_query = %s
offset=%d, num_rows=%d
\n", $Query_String, $offset, $num_rows); + + if (!IsSet($num_rows) || $num_rows < 1) + $num_rows = $phpgw_info['user']['preferences']['common']['maxmatchs']; + + $Query_String .= ' LIMIT ' . $offset . ',' . $num_rows; + + $this->Query_ID = @mysql_query($Query_String, $this->Link_ID); + $this->Row = 0; + $this->Errno = mysql_errno(); + $this->Error = mysql_error(); + if (!$this->Query_ID) + $this->halt('Invalid SQL: ' . $Query_String, $line, $file); + + return $this->Query_ID; + } + /* public: walk result set */ function next_record() { if (!$this->Query_ID) { @@ -466,4 +505,4 @@ class db { /*return $return; */ } } -?> \ No newline at end of file +?>