15 private $_errorCode = NULL;
16 private $_errorMessage = NULL;
21 if (defined(
"GAME_DB_CHARSET") && GAME_DB_CHARSET) {
22 $dbCharset = GAME_DB_CHARSET;
25 if (defined(
"GAME_DB_OPTIONS") && GAME_DB_OPTIONS) {
26 $dbOptions = GAME_DB_OPTIONS;
28 $dsn = sprintf(
"%s:host=%s;port=%d;dbname=%s;charset=%s", $this->_dbType, $this->_dbServer, $this->_dbPort, $this->_dbName, $dbCharset);
29 $this->_connection =
new PDO($dsn, $this->_dbUser, $this->_dbPass, $dbOptions);
31 $this->_connection = NULL;
32 $this->_errorCode = $e->getCode();
33 $this->_errorMessage = $e->getMessage();
41 $this->_connection = NULL;
45 if ($this->_connection) {
52 return $this->_errorMessage;
56 return $this->_errorCode;
60 if ($this->_connection) {
61 return $this->_connection->lastInsertId($name);
66 if ($this->_connection) {
67 return $this->_connection->rowCount();
72 private function _Fetch($result, $result_type) {
74 return $result->fetch($result_type);
80 if ($this->_connection) {
81 return $this->_Fetch($result, PDO::FETCH_ASSOC);
87 if ($this->_connection) {
88 return $this->_Fetch($result, PDO::FETCH_NUM);
94 if ($this->_connection && $query) {
96 if (Utils::StartsWith($query,
"SELECT", TRUE)) {
97 $stmt = $this->_connection->prepare($query);
98 if ($stmt->execute()) {
103 if ($this->_connection->query($query)) {
107 $this->_errorNumber = $e->getCode();
108 $this->_errorMessage = $e->getMessage();
115 if ($this->_connection) {
116 $quoted = $this->_connection->quote($text);
117 return substr($quoted, 1, strlen($quoted) - 2);
123 if ($this->_connection) {
124 return $this->_connection->beginTransaction();
130 if ($this->_connection) {
131 return $this->_connection->commit();
137 if ($this->_connection) {
138 return $this->_connection->rollBack();