|
23 | 23 | class MySQL { |
24 | 24 |
|
25 | 25 | // Base variables |
26 | | - var $lastError; // Holds the last error |
27 | | - var $lastQuery; // Holds the last query |
28 | | - var $result; // Holds the MySQL query result |
29 | | - var $records; // Holds the total number of records returned |
30 | | - var $affected; // Holds the total number of records affected |
31 | | - var $rawResults; // Holds raw 'arrayed' results |
32 | | - var $arrayedResult; // Holds an array of the result |
| 26 | + private $lastError; // Holds the last error |
| 27 | + private $lastQuery; // Holds the last query |
| 28 | + private $result; // Holds the MySQL query result |
| 29 | + private $records; // Holds the total number of records returned |
| 30 | + private $affected; // Holds the total number of records affected |
| 31 | + private $rawResults; // Holds raw 'arrayed' results |
| 32 | + private $arrayedResult; // Holds an array of the result |
33 | 33 |
|
34 | | - var $hostname; // MySQL Hostname |
35 | | - var $username; // MySQL Username |
36 | | - var $password; // MySQL Password |
37 | | - var $database; // MySQL Database |
| 34 | + private $hostname; // MySQL Hostname |
| 35 | + private $username; // MySQL Username |
| 36 | + private $password; // MySQL Password |
| 37 | + private $database; // MySQL Database |
38 | 38 |
|
39 | | - var $databaseLink; // Database Connection Link |
| 39 | + private $databaseLink; // Database Connection Link |
40 | 40 |
|
41 | 41 |
|
42 | 42 |
|
43 | 43 | /* ******************* |
44 | 44 | * Class Constructor * |
45 | 45 | * *******************/ |
46 | 46 |
|
47 | | - function __construct($database, $username, $password, $hostname='localhost', $port=3306){ |
| 47 | + function __construct($database, $username, $password, $hostname='localhost', $port=3306, $persistant = false){ |
48 | 48 | $this->database = $database; |
49 | 49 | $this->username = $username; |
50 | 50 | $this->password = $password; |
51 | 51 | $this->hostname = $hostname.':'.$port; |
52 | 52 |
|
53 | | - $this->Connect(); |
| 53 | + $this->Connect($persistant); |
54 | 54 | } |
55 | 55 |
|
56 | 56 | /* ******************* |
@@ -85,6 +85,8 @@ private function Connect($persistant = false){ |
85 | 85 | $this->lastError = 'Could not connect to database: ' . mysql_error($this->databaseLink); |
86 | 86 | return false; |
87 | 87 | } |
| 88 | + |
| 89 | + $this->setCharset(); // TODO: remove forced charset find out a specific management |
88 | 90 | return true; |
89 | 91 | } |
90 | 92 |
|
@@ -124,7 +126,8 @@ private function SecureData($data, $types){ |
124 | 126 | private function CleanData($data, $type = ''){ |
125 | 127 | switch($type) { |
126 | 128 | case 'none': |
127 | | - $data = $data; |
| 129 | + // useless do not reaffect just do nothing |
| 130 | + //$data = $data; |
128 | 131 | break; |
129 | 132 | case 'str': |
130 | 133 | $data = settype( $data, 'string'); |
@@ -197,7 +200,18 @@ public function executeSQL($query){ |
197 | 200 | } |
198 | 201 | } |
199 | 202 |
|
| 203 | + public function commit(){ |
| 204 | + return mysql_query("COMMIT", $this->databaseLink); |
| 205 | + } |
| 206 | + |
| 207 | + public function rollback(){ |
| 208 | + return mysql_query("ROLLBACK", $this->databaseLink); |
| 209 | + } |
200 | 210 |
|
| 211 | + public function setCharset( $charset = 'UTF8' ) { |
| 212 | + return mysql_set_charset ( $this->SecureData($charset,'string'), $this->databaseLink); |
| 213 | + } |
| 214 | + |
201 | 215 | // Adds a record to the database based on the array key names |
202 | 216 | public function insert($table, $vars, $exclude = '', $datatypes){ |
203 | 217 |
|
@@ -378,6 +392,8 @@ public function countRows($from, $where=''){ |
378 | 392 | // Closes the connections |
379 | 393 | public function closeConnection(){ |
380 | 394 | if($this->databaseLink){ |
| 395 | + // Commit before closing just in case :) |
| 396 | + $this->commit(); |
381 | 397 | mysql_close($this->databaseLink); |
382 | 398 | } |
383 | 399 | } |
|
0 commit comments