summaryrefslogtreecommitdiffstats
path: root/chat/lib/class/AJAXChatMySQLQuery.php
diff options
context:
space:
mode:
authorFrug <frugen@gmail.com>2012-10-10 15:46:25 -0400
committerFrug <frugen@gmail.com>2012-10-18 19:38:32 -0400
commitf138ecf192b0cd2cc59a77315a3de82902ddc2a9 (patch)
tree7098f577417962135d6eaf03a225d306fa912313 /chat/lib/class/AJAXChatMySQLQuery.php
parent339afb085ce26321d3bf342eb0b65220f2ecb7bb (diff)
downloadAJAX-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/AJAXChatMySQLQuery.php')
-rw-r--r--chat/lib/class/AJAXChatMySQLQuery.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/chat/lib/class/AJAXChatMySQLQuery.php b/chat/lib/class/AJAXChatMySQLQuery.php
new file mode 100644
index 0000000..d33b0d8
--- /dev/null
+++ b/chat/lib/class/AJAXChatMySQLQuery.php
@@ -0,0 +1,89 @@
+<?php
+/*
+ * @package AJAX_Chat
+ * @author Sebastian Tschan
+ * @copyright (c) Sebastian Tschan
+ * @license GNU Affero General Public License
+ * @link https://blueimp.net/ajax/
+ */
+
+// Class to perform SQL (MySQL) queries:
+class AJAXChatMySQLQuery {
+
+ var $_connectionID;
+ var $_sql = '';
+ var $_result = 0;
+ var $_errno = 0;
+ var $_error = '';
+
+ // Constructor:
+ function AJAXChatMySQLQuery($sql, $connectionID = null) {
+ $this->_sql = trim($sql);
+ $this->_connectionID = $connectionID;
+ if($this->_connectionID) {
+ $this->_result = mysql_query($this->_sql, $this->_connectionID);
+ if(!$this->_result) {
+ $this->_errno = mysql_errno($this->_connectionID);
+ $this->_error = mysql_error($this->_connectionID);
+ }
+ } else {
+ $this->_result = mysql_query($this->_sql);
+ if(!$this->_result) {
+ $this->_errno = mysql_errno();
+ $this->_error = mysql_error();
+ }
+ }
+ }
+
+ // Returns true if an error occured:
+ function error() {
+ // Returns true if the Result-ID is valid:
+ return !(bool)($this->_result);
+ }
+
+ // Returns an Error-String:
+ function getError() {
+ if($this->error()) {
+ $str = 'Query: ' .$this->_sql ."\n";
+ $str .= 'Error-Report: ' .$this->_error."\n";
+ $str .= 'Error-Code: '.$this->_errno;
+ } else {
+ $str = "No errors.";
+ }
+ return $str;
+ }
+
+ // Returns the content:
+ function fetch() {
+ if($this->error()) {
+ return null;
+ } else {
+ return mysql_fetch_assoc($this->_result);
+ }
+ }
+
+ // Returns the number of rows (SELECT or SHOW):
+ function numRows() {
+ if($this->error()) {
+ return null;
+ } else {
+ return mysql_num_rows($this->_result);
+ }
+ }
+
+ // Returns the number of affected rows (INSERT, UPDATE, REPLACE or DELETE):
+ function affectedRows() {
+ if($this->error()) {
+ return null;
+ } else {
+ return mysql_affected_rows($this->_connectionID);
+ }
+ }
+
+ // Frees the memory:
+ function free() {
+ @mysql_free_result($this->_result);
+ }
+
+}
+?> \ No newline at end of file