private static $dateFormat = '\'%Y-%m-%d %H:%M:%S\'';\r
\r
/**\r
+ * DB::setConnectionInfo()\r
* Set the information to connect to the database, it will attempt to connect.\r
* @param string $engine Engine\r
* @param string $host Host\r
}\r
\r
/**\r
+ * DB::disConnect()\r
* Disconnect the connection to the database.\r
*/\r
public static function disConnect()\r
}\r
\r
/**\r
+ * DB::getExecCount()\r
* To get the number of times you run the statement.\r
* @return int Number of executions\r
*/\r
}\r
\r
/**\r
+ * DB::formatDateTime()\r
* The value converted to a format that can be passed to the database datetime.\r
* @param int $timestamp UNIX timestamp\r
* @param int $offset timestamp offset\r
}\r
\r
/**\r
+ * DB::getValue()\r
* Gets the value of the first column of the first row of the results obtained in the statement.\r
* @param string $statement SQL Statement\r
* @return mixed Result value. If the call fails, it will return FALSE.\r
{\r
if ( self::$dbh == null ) return FALSE;\r
self::$execCount++;\r
- $stmt = &self::$dbh->query($statement);\r
- if ( $result = $stmt->fetch(PDO::FETCH_NUM) )\r
+ $result = self::showErrorDisplay(self::$dbh->query($statement));\r
+ if ( $row = $result->fetch(PDO::FETCH_NUM) )\r
{\r
- return $result[0];\r
+ return $row[0];\r
}\r
return FALSE;\r
}\r
\r
/**\r
+ * DB::getRow()\r
* Gets the first row of the results obtained in the statement.\r
* @param string $statement SQL Statement\r
* @return array Result row. If the call fails, it will return FALSE.\r
{\r
if ( self::$dbh == null ) return FALSE;\r
self::$execCount++;\r
- return self::$dbh->query($statement)->fetch(PDO::FETCH_BOTH);\r
+ $result = self::showErrorDisplay(self::$dbh->query($statement));\r
+ return $result->fetch(PDO::FETCH_BOTH);\r
}\r
\r
/**\r
+ * DB::getResult()\r
* Gets the set of results obtained in the statement.\r
* @param string $statement SQL Statement\r
* @return PDOStatement Result set object. If the call fails, it will return FALSE.\r
{\r
if ( self::$dbh == null ) return FALSE;\r
self::$execCount++;\r
- return self::$dbh->query($statement);\r
+ return self::showErrorDisplay(self::$dbh->query($statement));\r
}\r
\r
/**\r
+ * DB::execute()\r
* Execute an SQL statement and return the number of affected rows.\r
* @param string $statement SQL Statement\r
* @return int number of rows that were modified or deleted by the SQL statement you issued.\r
{\r
if ( self::$dbh == null ) return FALSE;\r
self::$execCount++;\r
- return self::$dbh->exec($statement);\r
+ return self::showErrorDisplay(self::$dbh->exec($statement));\r
+ }\r
+\r
+ /**\r
+ * DB::showErrorDisplay()\r
+ * On the display query execution result query has an error in the case of FALSE.\r
+ * @param mixed $result Query execution result\r
+ * @return mixes Query execution result\r
+ */\r
+ private static function showErrorDisplay($result)\r
+ {\r
+ global $CONF;\r
+ if ( array_key_exists('debug', $CONF) && $CONF['debug'] )\r
+ {\r
+ if ( $result === FALSE )\r
+ {\r
+ $err = self::getError();\r
+ print('mySQL error with query $query: ' . $err[2]);\r
+ }\r
+ }\r
+ return $result;\r
}\r
\r
/**\r
+ * DB::getError()\r
* Gets the error information associated with the last operation.\r
* @return array Error info\r
*/\r
}\r
\r
/**\r
+ * DB::quoteValue()\r
* Quotes a string for use in a query.\r
* @param string $value Value to quote\r
* @return string Quoted value\r
}\r
\r
/**\r
+ * DB::getInsertId()\r
* Get the value of the ID of the rows that are inserted at the end.\r
* @return string ID of the row\r
*/\r
}\r
\r
/**\r
+ * DB::getAttribute()\r
* Gets the attribute of the database.\r
* @return string Attribute\r
*/\r