Skip to content

Commit 9ae008a

Browse files
committed
Update class.MySQL.php
Set attributes to private Added commit and rollback methods; Added charset management (experimental); Removed useless setting. Forces commit before closing.
1 parent 57f0507 commit 9ae008a

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

class.MySQL.php

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@
2323
class MySQL {
2424

2525
// 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
3333

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
3838

39-
var $databaseLink; // Database Connection Link
39+
private $databaseLink; // Database Connection Link
4040

4141

4242

4343
/* *******************
4444
* Class Constructor *
4545
* *******************/
4646

47-
function __construct($database, $username, $password, $hostname='localhost', $port=3306){
47+
function __construct($database, $username, $password, $hostname='localhost', $port=3306, $persistant = false){
4848
$this->database = $database;
4949
$this->username = $username;
5050
$this->password = $password;
5151
$this->hostname = $hostname.':'.$port;
5252

53-
$this->Connect();
53+
$this->Connect($persistant);
5454
}
5555

5656
/* *******************
@@ -85,6 +85,8 @@ private function Connect($persistant = false){
8585
$this->lastError = 'Could not connect to database: ' . mysql_error($this->databaseLink);
8686
return false;
8787
}
88+
89+
$this->setCharset(); // TODO: remove forced charset find out a specific management
8890
return true;
8991
}
9092

@@ -124,7 +126,8 @@ private function SecureData($data, $types){
124126
private function CleanData($data, $type = ''){
125127
switch($type) {
126128
case 'none':
127-
$data = $data;
129+
// useless do not reaffect just do nothing
130+
//$data = $data;
128131
break;
129132
case 'str':
130133
$data = settype( $data, 'string');
@@ -197,7 +200,18 @@ public function executeSQL($query){
197200
}
198201
}
199202

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+
}
200210

211+
public function setCharset( $charset = 'UTF8' ) {
212+
return mysql_set_charset ( $this->SecureData($charset,'string'), $this->databaseLink);
213+
}
214+
201215
// Adds a record to the database based on the array key names
202216
public function insert($table, $vars, $exclude = '', $datatypes){
203217

@@ -378,6 +392,8 @@ public function countRows($from, $where=''){
378392
// Closes the connections
379393
public function closeConnection(){
380394
if($this->databaseLink){
395+
// Commit before closing just in case :)
396+
$this->commit();
381397
mysql_close($this->databaseLink);
382398
}
383399
}

0 commit comments

Comments
 (0)