From 724ad4505628d493b43b4f585512d67dc0b4ee76 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 18 Jan 2014 23:49:39 -0800 Subject: add ajaxchat library - needs a lot of integration work to handle decentralisation (e.g. chatroom@website) and zotid w/permissions (e.g. ACL controlled chatrooms); we can also rip out a lot of stuff we don't need. --- .../chat/lib/class/AJAXChatMySQLDataBase.php | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 library/ajaxchat/chat/lib/class/AJAXChatMySQLDataBase.php (limited to 'library/ajaxchat/chat/lib/class/AJAXChatMySQLDataBase.php') diff --git a/library/ajaxchat/chat/lib/class/AJAXChatMySQLDataBase.php b/library/ajaxchat/chat/lib/class/AJAXChatMySQLDataBase.php new file mode 100644 index 000000000..6dca348d1 --- /dev/null +++ b/library/ajaxchat/chat/lib/class/AJAXChatMySQLDataBase.php @@ -0,0 +1,92 @@ +_connectionID = $dbConnectionConfig['link']; + $this->_dbName = $dbConnectionConfig['name']; + } + + // Method to connect to the DataBase server: + function connect(&$dbConnectionConfig) { + $this->_connectionID = @mysql_connect( + $dbConnectionConfig['host'], + $dbConnectionConfig['user'], + $dbConnectionConfig['pass'], + true + ); + if(!$this->_connectionID) { + $this->_errno = null; + $this->_error = 'Database connection failed.'; + return false; + } + return true; + } + + // Method to select the DataBase: + function select($dbName) { + if(!@mysql_select_db($dbName, $this->_connectionID)) { + $this->_errno = mysql_errno($this->_connectionID); + $this->_error = mysql_error($this->_connectionID); + 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 "'".mysql_real_escape_string($value, $this->_connectionID)."'"; + } + + // Method to perform SQL queries: + function sqlQuery($sql) { + return new AJAXChatMySQLQuery($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 mysql_insert_id($this->_connectionID); + } + +} +?> \ No newline at end of file -- cgit v1.2.3