diff options
author | Frug <frugen@gmail.com> | 2012-10-10 15:46:25 -0400 |
---|---|---|
committer | Frug <frugen@gmail.com> | 2012-10-18 19:38:32 -0400 |
commit | f138ecf192b0cd2cc59a77315a3de82902ddc2a9 (patch) | |
tree | 7098f577417962135d6eaf03a225d306fa912313 /chat/lib/class/AJAXChatMySQLiDataBase.php | |
parent | 339afb085ce26321d3bf342eb0b65220f2ecb7bb (diff) | |
download | AJAX-Chat-f138ecf192b0cd2cc59a77315a3de82902ddc2a9.zip AJAX-Chat-f138ecf192b0cd2cc59a77315a3de82902ddc2a9.tar.gz AJAX-Chat-f138ecf192b0cd2cc59a77315a3de82902ddc2a9.tar.bz2 |
Updated everything to 0.8.5a0.8.5a
Update readme.md
Diffstat (limited to 'chat/lib/class/AJAXChatMySQLiDataBase.php')
-rw-r--r-- | chat/lib/class/AJAXChatMySQLiDataBase.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/chat/lib/class/AJAXChatMySQLiDataBase.php b/chat/lib/class/AJAXChatMySQLiDataBase.php new file mode 100644 index 0000000..5b988e0 --- /dev/null +++ b/chat/lib/class/AJAXChatMySQLiDataBase.php @@ -0,0 +1,91 @@ +<?php +/* + * @package AJAX_Chat + * @author Sebastian Tschan + * @copyright (c) Sebastian Tschan + * @license GNU Affero General Public License + * @link https://blueimp.net/ajax/ + */ + +// Class to initialize the MySQL DataBase connection: +class AJAXChatDataBaseMySQLi { + + var $_connectionID; + var $_errno = 0; + var $_error = ''; + var $_dbName; + + function AJAXChatDataBaseMySQLi(&$dbConnectionConfig) { + $this->_connectionID = $dbConnectionConfig['link']; + $this->_dbName = $dbConnectionConfig['name']; + } + + // Method to connect to the DataBase server: + function connect(&$dbConnectionConfig) { + $this->_connectionID = new mysqli( + $dbConnectionConfig['host'], + $dbConnectionConfig['user'], + $dbConnectionConfig['pass'] + ); + if(!$this->_connectionID) { + $this->_errno = mysqli_connect_errno(); + $this->_error = mysqli_connect_error(); + return false; + } + return true; + } + + // Method to select the DataBase: + function select($dbName) { + if(!$this->_connectionID->select_db($dbName)) { + $this->_errno = $this->_connectionID->errno; + $this->_error = $this->_connectionID->error; + return false; + } + $this->_dbName = $dbName; + return true; + } + + // Method to determine if an error has occured: + function error() { + return (bool)$this->_error; + } + + // Method to return the error report: + function getError() { + if($this->error()) { + $str = 'Error-Report: ' .$this->_error."\n"; + $str .= 'Error-Code: '.$this->_errno."\n"; + } else { + $str = 'No errors.'."\n"; + } + return $str; + } + + // Method to return the connection identifier: + function &getConnectionID() { + return $this->_connectionID; + } + + // Method to prevent SQL injections: + function makeSafe($value) { + return "'".$this->_connectionID->escape_string($value)."'"; + } + + // Method to perform SQL queries: + function sqlQuery($sql) { + return new AJAXChatMySQLiQuery($sql, $this->_connectionID); + } + + // Method to retrieve the current DataBase name: + function getName() { + return $this->_dbName; + } + + // Method to retrieve the last inserted ID: + function getLastInsertedID() { + return $this->_connectionID->insert_id; + } + +} +?>
\ No newline at end of file |