| [ Index ] |
PHP Cross Reference of Drupal 6 (heimberg) |
[Summary view] [Print] [Text view]
1 2 <? 3 /* 4 * PHP Freaks Code Library 5 * http://www.phpfreaks.com/quickcode.php 6 * 7 * Title: Dblib 1.2 8 * Version: 1.0 9 * Author: Vladimir Gorej aka(char0n) 10 * Date: Friday, 12/23/2005 - 05:40 AM 11 * 12 * 13 * 14 * NOTICE: This code is available from PHPFreaks.com code Library. 15 * This code is not Copyrighted by PHP Freaks. 16 * 17 * PHP Freaks does not claim authorship of this code. 18 * 19 * This code was submitted to our website by a user. 20 * 21 * The user may or may not claim authorship of this code. 22 * 23 * If there are any questions about the origin of this code, 24 * please contact the person who submitted it, not PHPFreaks.com! 25 * 26 * USE THIS CODE AT YOUR OWN RISK! NO GUARANTEES ARE GIVEN! 27 * 28 * SHAMELESS PLUG: Need WebHosting? Checkout WebHost Freaks: 29 * http://www.webhostfreaks.com 30 * WebHosting by PHP Freaks / The Web Freaks! 31 */ 32 33 34 // * Description / Example: 35 // * 36 // * This is the database class i wrote to make my work with databases comfortable and reduce the code size of my scripts. The class is called simply DbLib. You can support different dbs by writing a new derived classes. Since there is only MySQL support. Feel free to write new dbs extensions for it. 37 38 ?> 39 40 <?php 41 /*! @class Sql Library Class version 1.2 (later just DbLib) 42 @author char0n (May 11 2005) 43 @abstract DbLib for operating actions with Sql databases 44 @discussion DbLib can be easily extended and used for many dbs 45 46 @licence GNU General Public Licence, Version 2, june 1991 47 This program is distributed in the hope that it will be useful, 48 but WITHOUT ANY WARRANTY 49 You should have received a copy of the GNU General Public License 50 along with this program 51 */ 52 53 /////////////////////////////////////////////////////////////////////////////// 54 // DbLib base class defines the basic operations. You can support 55 // different dbs by writing a new derived class 56 57 class DbLib 58 { 59 60 var $mHost = 'mysql5a.appliedi.net'; 61 var $mPort = 3306; 62 var $mUser = 'heimberglaw'; 63 var $mPassword = 'medmal123'; 64 var $mDatabase = 'heimberglaw'; 65 var $defcharset = 'latin1'; 66 var $mSocket; 67 var $mResult; 68 var $mRow; 69 70 71 function OpenConnection() { $this->mSocket = 1; } 72 function SelectDatabase() { $this->IsConnected(); } 73 function DbQuery() { $this->IsConnected(); } 74 function Query() { $this->IsConnected(); } 75 function GetResult() { $this->IsConnected(); } 76 function GetNumRows() { $this->IsConnected(); } 77 function GetNextRecord() { $this->IsConnected(); } 78 function GetField() { $this->IsConnected(); } 79 function FreeResult() { $this->IsConnected(); } 80 function GetAffectedRows() { $this->IsConnected(); } 81 function GetLastID() { $this->IsConnected(); } 82 function CloseConnection() { $this->IsConnected(); } 83 function GetError() { $this->IsConnected(); } 84 function SqlCorrection() { $this->IsConnected(); } 85 function __wakeup() { $this->OpenConnection(); } 86 function __sleep() { $this->CloseConnection(); } 87 function ResetRecordSet() { $this->IsConnected(); } 88 function IsConnected() 89 { 90 if (!$this->mSocket) die('Not connected to database server'); 91 } 92 93 } 94 95 /////////////////////////////////////////////////////////////////////////////// 96 // MySQL database support 97 class DbLibMySQL extends DbLib 98 { 99 100 function DbLibMySQL($host = 0, $port = 0, $user = 0, $password = 0, $database = 0) 101 { 102 if ($host) $this->mHost = $host; 103 if ($port) $this->mPort = $port; 104 if ($user) $this->mUser = $user; 105 if ($password) $this->mPassword = $password; 106 if ($database) $this->mDatabase = $database; 107 } 108 109 110 function OpenConnection() 111 { 112 parent::OpenConnection(); 113 $this->mSocket = @mysql_connect($this->mHost . ':' . $this->mPort, $this->mUser, $this->mPassword) 114 or die($this->GetError()); 115 @mysql_select_db($this->mDatabase,$this->mSocket) 116 or die($this->GetError()); 117 //$this->DbQuery(\"SET NAMES '{$this->DefCharset}'"); 118 return $this->mSocket; 119 } 120 121 122 function SelectDatabase($database = '') 123 { 124 parent::SelectDatabase(); 125 @mysql_select_db($database,$this->mSocket) or die($this->GetError()); 126 $this->mDatabase = $database; 127 } 128 129 130 function DbQuery($query = '') 131 { 132 parent::DbQuery(); 133 @mysql_unbuffered_query($query,$this->mSocket) or die($this->GetError()); 134 } 135 136 137 function Query($query = '') 138 { 139 parent::Query(); 140 ($this->mResult = @mysql_query($query,$this->mSocket)) or die($this->GetError()); 141 return $this->mResult; 142 } 143 144 145 function GetResult($row = 0, $coll = 0, $result = 0) 146 { 147 parent::GetResult(); 148 ($result) ? $temp_result = $result : $temp_result = $this->mResult; 149 150 if (!is_resource($temp_result)) die('Not MySQL resource while getting results'); 151 return @mysql_result($temp_result,$row,$coll); 152 } 153 154 155 function GetNumRows($result = 0) 156 { 157 parent::GetNumRows(); 158 ($result) ? $temp_result = $result : $temp_result = $this->mResult; 159 160 if (!is_resource($temp_result)) die('Not MySQL resource while getting results'); 161 return @mysql_num_rows($temp_result); 162 } 163 164 function GetAffectedRows() 165 { 166 parent::GetAffectedRows(); 167 return @mysql_affected_rows($this->mSocket); 168 } 169 170 function GetLastID() 171 { 172 parent::GetLastID(); 173 return @mysql_insert_id($this->mSocket); 174 } 175 176 function GetNextRecord($result = 0) 177 { 178 parent::GetNextRecord(); 179 ($result) ? $temp_result = $result : $temp_result = $this->mResult; 180 181 if (!is_resource($temp_result)) die('Not MySQL resource while getting results'); 182 183 $this->mRow = @mysql_fetch_assoc($temp_result); 184 return $this->mRow != FALSE; 185 } 186 187 function GetField($field = '') 188 { 189 parent::GetField(); 190 return $this->mRow[$field]; 191 } 192 193 194 function FreeResult($result = 0) 195 { 196 parent::FreeResult(); 197 if ($result) $temp_result = $result; 198 else $temp_result = $this->mResult; 199 200 if (!is_resource($temp_result)) die('Not MySQL resource while freeing results'); 201 @mysql_free_result($temp_result); 202 } 203 204 205 function SqlCorrection($string) 206 { 207 parent::SqlCorrection(); 208 return @mysql_real_escape_string($string); 209 } 210 211 212 function GetError() 213 { 214 parent::GetError(); 215 return @mysql_error(); 216 } 217 218 219 function CloseConnection() 220 { 221 parent::CloseConnection(); 222 @mysql_close($this->mSocket) or die('There is no valid MySQL-Link resource'); 223 } 224 225 function ResetRecordSet() 226 { 227 parent::ResetRecordSet(); 228 @mysql_data_seek($this->mResult, 0); 229 } 230 231 } 232 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 23 13:22:29 2011 | Cross-referenced by PHPXref 0.7 |