Created
May 14, 2012 14:25
-
-
Save franz-isx/2694303 to your computer and use it in GitHub Desktop.
TeamCal Opti 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: includes/db.class.php | |
=================================================================== | |
--- includes/db.class.php (Revision 109) | |
+++ includes/db.class.php (Revision 112) | |
@@ -29,8 +29,9 @@ | |
var $db_user = ''; | |
var $db_pass = ''; | |
var $db_persistent = ''; | |
- var $db_handle = ''; | |
+ static $db_handle = ''; | |
var $db_errortxt = ''; | |
+ static $query_cache = array(); | |
/** | |
* Constructor reading server and database information from the | |
@@ -53,23 +54,24 @@ | |
*/ | |
function db_connect() | |
{ | |
+ if (!myDB::$db_handle) | |
switch ($this->db_type) { | |
case 1 : // MySQL | |
if ($this->db_persistent) { | |
- $this->db_handle = @ mysql_pconnect($this->db_server, $this->db_user, $this->db_pass); | |
+ myDB::$db_handle = @ mysql_pconnect($this->db_server, $this->db_user, $this->db_pass); | |
} else { | |
- $this->db_handle = @ mysql_connect($this->db_server, $this->db_user, $this->db_pass); | |
+ myDB::$db_handle = @ mysql_connect($this->db_server, $this->db_user, $this->db_pass); | |
} | |
- if (!$this->db_handle) { | |
+ if (!myDB::$db_handle) { | |
$errtxt = "Connecting to mySQL server " . $this->db_server . " failed."; | |
$this->db_error($errtxt, "db_connect()", true); | |
return; | |
} | |
- if (!@ mysql_select_db($this->db_name, $this->db_handle)) { | |
- $errtxt = " | |
+ if (!@ mysql_select_db($this->db_name, myDB::$db_handle)) { | |
+ $errtxt = "s | |
Error: Connection to MySQL database " . $this->db_server . "/" . $this->db_name . " failed.<BR> | |
- Code: " . @ mysql_errno($this->db_handle) . ",<BR> | |
- Message: " . @ mysql_error($this->db_handle) . " | |
+ Code: " . @ mysql_errno(myDB::$db_handle) . ",<BR> | |
+ Message: " . @ mysql_error(myDB::$db_handle) . " | |
"; | |
$this->db_error($errtxt, "db_connect()", true); | |
} | |
@@ -87,11 +89,24 @@ | |
{ | |
switch ($this->db_type) { | |
case 1 : // MySQL | |
- $result = mysql_query($query, $this->db_handle); | |
- if (!$result) { | |
- echo "Error: A problem was encountered while executing this query:<br><br>\n\n$query<br><br>\n\n"; | |
- die("Error: Fatal database error!<br>\n"); | |
+ $upp_query = strtoupper($query); | |
+ if (strpos($upp_query, 'UPDATE') || strpos($upp_query, 'INSERT') || strpos($upp_query, 'DELETE')){ | |
+ // we're changing the database so throw away the cache | |
+ myDB::$query_cache = array(); | |
} | |
+ if (!array_key_exists($query, myDB::$query_cache)){ | |
+ $result = mysql_query($query, myDB::$db_handle); | |
+ if (!$result) { | |
+ echo "Error: A problem was encountered while executing this query:<br><br>\n\n$query<br><br>\n\n"; | |
+ die("Error: Fatal database error!<br>\n"); | |
+ } | |
+ myDB::$query_cache[$query] = $result; | |
+ } else { | |
+ $result = myDB::$query_cache[$query]; | |
+ if (mysql_num_rows($result) > 0){ | |
+ mysql_data_seek($result, 0); | |
+ } | |
+ } | |
break; | |
} | |
return $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment