blob: 9bc611e2de611da151b93b41aaf001516d271e9f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
/*
* @package AJAX_Chat
* @author Sebastian Tschan
* @copyright (c) Sebastian Tschan
* @license Modified MIT 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 __construct(&$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->connect_errno) {
$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;
}
}
?>
|