11 $name = $class::TABLE_NAME;
12 if (defined(
"GAME_DB_PREFIX") && GAME_DB_PREFIX) {
13 $name = GAME_DB_PREFIX . $name;
16 return $quote . trim(str_replace($quote,
"", $name)) . $quote;
28 $res = $Database->Query(
"SELECT * FROM $tableName WHERE $filter");
30 $row = $Database->FetchAssoc($res);
32 $this->_loadByRow($row);
42 protected function _loadByRow($row, $stripSlashes =
false, $callbackOnExists =
false) {
43 Utils::FillObjectFromRow($this, $row, $stripSlashes, $callbackOnExists);
52 protected static function _count($tableName, $filter = null) {
54 $query =
"SELECT COUNT(*) FROM (SELECT * FROM " . $tableName;
55 if ($filter != null) {
56 $query .=
" WHERE " . $filter;
59 $res = $Database->Query($query);
61 $row = $Database->FetchNum($res);
63 return intval($row[0]);
80 protected static function _load($tableName, $returnedClass =
"", $where =
"", $order = null, $limit = null, $offset = null, &$count = null) {
81 return self::_loadEx(null, $tableName, $returnedClass, $where, $order, $limit, $offset, $count);
84 protected static function _loadEx($select, $from, $returnedClass =
"", $where =
"", $order = null, $limit = null, $offset = null, &$count = null, $debug =
false) {
85 if ($count !== null) {
87 $count = self::_count($from, $where);
90 $query =
"SELECT " . ($select ? $select :
"*") .
" FROM $from";
93 $query .=
" WHERE " . $where;
97 $query .=
" ORDER BY $order";
100 if ($limit != null) {
101 $query .=
" LIMIT " . ($offset > 0 ?
"$offset," :
"") . $limit;
104 if ($debug ===
true) {
105 AppLog::Info($query);
108 return self::_loadQuery($query, $returnedClass);
111 protected static function _loadQuery($query, $returnedClass =
"") {
114 $res = $Database->Query($query);
116 while ($row = $Database->FetchAssoc($res)) {
117 $rows[] = ($returnedClass ==
"" ? $row :
new $returnedClass($row));
130 return self::_loadQuery($query, $returnedClass);
140 return self::_count($tableName, $filter);
166 protected function _Delete($tableName, $filter = null) {
169 if ($Database->Query(
"DELETE FROM $tableName WHERE $filter")) {
181 return json_encode($this->ToArray());
185 return Utils::ObjectToArray($this);
194 $Database->Query(
"TRUNCATE " . $tableName);
201 return self::TruncateTable(self::GetTableName($class));
static TruncateClass($class)
_loadByRow($row, $stripSlashes=false, $callbackOnExists=false)
static GetTableName($class)
_loadFilter($tableName, $filter)
_Delete($tableName, $filter=null)
static _load($tableName, $returnedClass="", $where="", $order=null, $limit=null, $offset=null, &$count=null)
static CountRecords($tableName, $filter=null)
static TruncateTable($tableName)
static _loadEx($select, $from, $returnedClass="", $where="", $order=null, $limit=null, $offset=null, &$count=null, $debug=false)
static LoadRecords($query, $returnedClass="")
static _count($tableName, $filter=null)
static _loadQuery($query, $returnedClass="")