X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fxdb.php;h=d612ed8663786b8af385310c43a58e64f2ed73c2;hb=30a6f0799c941b1110f831f93c82ac5309250c29;hp=70b1f247b185715be047b24e215984a7ca06ff67;hpb=42a50827dc2ac2b13ddaf77ea16c0989cd8b960d;p=platal.git diff --git a/classes/xdb.php b/classes/xdb.php index 70b1f24..d612ed8 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -23,25 +23,21 @@ class XDB { var $_trace_data = array(); - // {{{ function _prepare - - function _prepare($args) { + public static function _prepare($args) { $query = array_map(Array('XDB', '_db_escape'), $args); $query[0] = str_replace('{?}', '%s', str_replace('%', '%%', $args[0])); return call_user_func_array('sprintf', $query); } - // }}} - // {{{ function _reformatQuery - - function _reformatQuery($query) + public static function _reformatQuery($query) { $query = preg_split("/\n\\s*/", $query); $length = 0; foreach ($query as $key=>$line) { $local = -2; if (preg_match('/^([A-Z]+(?:\s+(?:JOIN|BY|FROM|INTO))?)\s+(.*)/', $line, $matches) - && $matches[1] != 'AND' && $matches[1] != 'OR') { + && $matches[1] != 'AND' && $matches[1] != 'OR') + { $local = strlen($matches[1]); $line = $matches[1] . ' ' . $matches[2]; $length = max($length, $local); @@ -58,10 +54,7 @@ class XDB return $res; } - // }}} - // {{{ function _query - - function _query($query) { + public static function _query($query) { global $globals; if ($globals->debug & 1) { @@ -87,50 +80,32 @@ class XDB return $res; } - // }}} - // {{{ function query - - function &query() + public static function query() { return new XOrgDBResult(XDB::_prepare(func_get_args())); } - // }}} - // {{{ function execute() - - function execute() + public static function execute() { return XDB::_query(XDB::_prepare(func_get_args())); } - // }}} - // {{{ function iterator() - - function &iterator() + public static function iterator() { return new XOrgDBIterator(XDB::_prepare(func_get_args())); } - // }}} - // {{{ function iterRow() - - function &iterRow() + public static function iterRow() { return new XOrgDBIterator(XDB::_prepare(func_get_args()), MYSQL_NUM); } - // }}} - // {{{ function insertId() - - function insertId() + public static function insertId() { return mysql_insert_id(); } - // }}} - // {{{ function _db_escape - - function _db_escape($var) + public static function _db_escape($var) { switch (gettype($var)) { case 'boolean': @@ -156,57 +131,39 @@ class XDB } } - // }}} - - function trace_format(&$page, $template = 'database-debug.tpl') { - $page->assign('trace_data', $GLOBALS['XDB::trace_data']); - $page->assign('db_error', $GLOBALS['XDB::error']); + public static function trace_format(&$page, $template = 'database-debug.tpl') { + $page->assign('trace_data', @$GLOBALS['XDB::trace_data']); + $page->assign('db_error', @$GLOBALS['XDB::error']); return $page->fetch($template); } } class XOrgDBResult { - // {{{ properties var $_res; - // }}} - // {{{ constructor - function XOrgDBResult($query) { $this->_res = XDB::_query($query); } - // }}} - // {{{ destructor - function free() { mysql_free_result($this->_res); unset($this); } - // }}} - // {{{ function fetchRow - function _fetchRow() { return mysql_fetch_row($this->_res); } - // }}} - // {{{ function fetchAssoc - function _fetchAssoc() { return mysql_fetch_assoc($this->_res); } - // }}} - // {{{ function fetchAllRow - function fetchAllRow() { $result = Array(); @@ -216,9 +173,6 @@ class XOrgDBResult return $result; } - // }}} - // {{{ function fetchAllAssoc - function fetchAllAssoc() { $result = Array(); @@ -228,9 +182,6 @@ class XOrgDBResult return $result; } - // }}} - // {{{ function fetchOneAssoc() - function fetchOneAssoc() { $tmp = $this->_fetchAssoc(); @@ -238,9 +189,6 @@ class XOrgDBResult return $tmp; } - // }}} - // {{{ function fetchOneRow() - function fetchOneRow() { $tmp = $this->_fetchRow(); @@ -248,9 +196,6 @@ class XOrgDBResult return $tmp; } - // }}} - // {{{ function fetchOneCell() - function fetchOneCell() { $tmp = $this->_fetchRow(); @@ -258,9 +203,6 @@ class XOrgDBResult return $tmp[0]; } - // }}} - // {{{ function fetchColumn() - function fetchColumn($key = 0) { $res = Array(); @@ -277,30 +219,20 @@ class XOrgDBResult return $res; } - // }}} - // {{{ function numRows - function numRows() { return mysql_num_rows($this->_res); } - - // }}} } class XOrgDBIterator { - // {{{ properties + private $_result; + private $_pos; + private $_total; + private $_mode = MYSQL_ASSOC; - var $_result; - var $_pos; - var $_total; - var $_mode = MYSQL_ASSOC; - - // }}} - // {{{ constructor - - function XOrgDBIterator($query, $mode = MYSQL_ASSOC) + function __construct($query, $mode = MYSQL_ASSOC) { $this->_result =& new XOrgDBResult($query); $this->_pos = 0; @@ -308,9 +240,6 @@ class XOrgDBIterator $this->_mode = $mode; } - // }}} - // {{{ function next () - function next() { $this->_pos ++; @@ -322,31 +251,20 @@ class XOrgDBIterator return $this->_mode != MYSQL_ASSOC ? $this->_result->_fetchRow() : $this->_result->_fetchAssoc(); } - // }}} - // {{{ function first - function first() { return $this->_pos == 1; } - // }}} - // {{{ function last - function last() { return $this->_last == $this->_total; } - // }}} - // {{{ function total() - function total() { return $this->_total; } - - // }}} } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: