diff options
author | jhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6> | 2009-12-27 10:44:57 -0500 |
---|---|---|
committer | jhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6> | 2009-12-27 10:44:57 -0500 |
commit | d526decc4884710ae7fafe7aa5171e7f59b24292 (patch) | |
tree | 12c07f3ef6ab9bf5a4f278a7b00720996c41667d /includes/sql.class.php | |
parent | 07253dc75c69cf585ad39a218f3f2cf97b773987 (diff) | |
download | bayonetcms-d526decc4884710ae7fafe7aa5171e7f59b24292.tar.gz |
MySQL -> MySQLi
Fixed memory leaks after Fetching arrays
Removed all while loops that interfaced with $db->Fetch()
Rewrote RSS module
Fixed syntax error in donations module
Fixed link structure for news module
Reverting to old page display method
git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@402 c5b2fb0a-d05d-0410-98c8-828840a80ff6
Diffstat (limited to 'includes/sql.class.php')
-rw-r--r-- | includes/sql.class.php | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/includes/sql.class.php b/includes/sql.class.php index 0dcd0d5..3b93e2a 100644 --- a/includes/sql.class.php +++ b/includes/sql.class.php @@ -33,51 +33,38 @@ class Bayonet_SQL $this->hostname = $hostname; decho("Connecting ('$hostname')"); - return mysql_connect($hostname, $username, $passwd); + return ($GLOBALS['___mysqli_ston'] = mysqli_connect($hostname, $username, $passwd)); } public function Disconnect($link) { decho("Disconnecting ('$link' from '$this->hostname')"); - //return mysql_close($link); + return mysqli_close($GLOBALS['___mysqli_ston']); } public function Stat() { - return mysql_stat(); + return mysqli_stat($GLOBALS['___mysqli_ston']); } public function Select_db($db) { decho("Selecting database ('$db')"); - return mysql_select_db($db); + return mysqli_select_db($GLOBALS['___mysqli_ston'], $db); } public function Query($str) { global $db_queries; ++$db_queries; - //FIGURE OUT HOW TO CHECK EXCEPTION, TRY CATCH ??? - // if(!mysql_query($str)) - // { - // throw new Exception(mysql_error()); - // } - /* - try{ - - }catch(Exception $e){ - - } */ - - return mysql_query($str); + return mysqli_query($GLOBALS['___mysqli_ston'], $str); } public function Free($result) { global $db_frees; ++$db_frees; - decho("Freeing result"); - return mysql_free_result($result); + @((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false); } public function Fetch($result) @@ -85,42 +72,65 @@ class Bayonet_SQL return $this->FetchArray($result); } - public function FetchArray($result) - { - global $db_fetches; - ++$db_fetches; - /* Alias Fetch() prefered, so no decho information */ - decho("Fetching result"); - return mysql_fetch_array($result,MYSQL_ASSOC); - } + public function FetchArray($p_result) + { + global $db_fetches; + ++$db_fetches; + + decho('Fetching result'); + + while ($row = mysqli_fetch_array($p_result, MYSQLI_ASSOC)) { + $result[] = $row; + } + + $this->Free($p_result); + + return is_array($result) ? $result : array(); + } - public function FetchObject($result,$class) + public function FetchObject($p_result, $class) { global $db_fetches; ++$db_fetches; + decho("Fetching object result"); - return mysql_fetch_object($result,$class); + + while ($row = mysqli_fetch_object($p_result, $class)) { + (object)$result[] = $row; + } + + $this->Free($p_result); + + return is_object($result) ? $result : (object)array(); } public function FetchAssoc($result) - { - global $db_fetches; - ++$db_fetches; - decho("Fetching assoc result"); - return mysql_fetch_assoc($result); + { + return $this->FetchArray($result); } - public function FetchRow($result) + public function FetchRow($p_result) { + global $db_fetches; + ++$db_fetches; + decho("Fetching single row"); - return mysql_fetch_row($result); + + while ($row = mysqli_fetch_row($p_result)) { + $result[] = $row; + } + + $this->Free($p_result); + + return is_array($result) ? $result : array(); } public function Rows($result) { decho("Fetching number of rows"); - return mysql_num_rows($result); + + return mysqli_num_rows($result); } } -?>
\ No newline at end of file +?> |