2323class 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+ public $ lastError ; // Holds the last error
27+ public $ lastQuery ; // Holds the last query
28+ public $ result ; // Holds the MySQL query result
29+ public $ records ; // Holds the total number of records returned
30+ public $ affected ; // Holds the total number of records affected
31+ public $ rawResults ; // Holds raw 'arrayed' results
32+ public $ 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
56+ /* *******************
57+ * Class Destructor *
58+ * *******************/
5659
60+ function __destruct (){
61+ $ this ->closeConnection ();
62+ }
5763
5864 /* *******************
5965 * Private Functions *
@@ -79,6 +85,8 @@ private function Connect($persistant = false){
7985 $ this ->lastError = 'Could not connect to database: ' . mysql_error ($ this ->databaseLink );
8086 return false ;
8187 }
88+
89+ $ this ->setCharset (); // TODO: remove forced charset find out a specific management
8290 return true ;
8391 }
8492
@@ -118,7 +126,8 @@ private function SecureData($data, $types){
118126 private function CleanData ($ data , $ type = '' ){
119127 switch ($ type ) {
120128 case 'none ' :
121- $ data = $ data ;
129+ // useless do not reaffect just do nothing
130+ //$data = $data;
122131 break ;
123132 case 'str ' :
124133 $ data = settype ( $ data , 'string ' );
@@ -191,7 +200,18 @@ public function executeSQL($query){
191200 }
192201 }
193202
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+ }
194210
211+ public function setCharset ( $ charset = 'UTF8 ' ) {
212+ return mysql_set_charset ( $ this ->SecureData ($ charset ,'string ' ), $ this ->databaseLink );
213+ }
214+
195215 // Adds a record to the database based on the array key names
196216 public function insert ($ table , $ vars , $ exclude = '' , $ datatypes ){
197217
@@ -360,7 +380,7 @@ public function arrayResultsWithKey($key='id'){
360380
361381 // Returns last insert ID
362382 public function lastInsertID (){
363- return mysql_insert_id ();
383+ return mysql_insert_id ($ this -> databaseLink );
364384 }
365385
366386 // Return number of rows
@@ -372,7 +392,9 @@ public function countRows($from, $where=''){
372392 // Closes the connections
373393 public function closeConnection (){
374394 if ($ this ->databaseLink ){
395+ // Commit before closing just in case :)
396+ $ this ->commit ();
375397 mysql_close ($ this ->databaseLink );
376398 }
377399 }
378- }
400+ }
0 commit comments