diff --git a/src/Pluf/DB/Stats.php b/src/Pluf/DB/Stats.php new file mode 100644 index 0000000..b84944b --- /dev/null +++ b/src/Pluf/DB/Stats.php @@ -0,0 +1,84 @@ +_rdb = $db; + } + + public function __call($name, $args) + { + if (!in_array($name, array('execute', 'select'))) { + return call_user_func_array(array($this->_rdb, $name), $args); + } + Pluf_Log::stime('timer'); + $res = call_user_func_array(array($this->_rdb, $name), $args); + Pluf_Log::perf(array('Pluf_DB_Stats', $this->_rdb->lastquery, Pluf_Log::etime('timer', 'total_sql'))); + Pluf_Log::inc('sql_query'); + return $res; + } + + public function __get($name) + { + return $this->_rdb->$name; + } + + public function __set($name, $value) + { + return $this->_rdb->$name = $value; + } +} + +function Pluf_DB_Stats_getConnection($extra=null) +{ + if (isset($GLOBALS['_PX_db']) && + (is_resource($GLOBALS['_PX_db']->con_id) or is_object($GLOBALS['_PX_db']->con_id))) { + return $GLOBALS['_PX_db']; + } + $GLOBALS['_PX_db'] = new Pluf_DB_Stats( + Pluf_DB::get(Pluf::f('db_engine'), + Pluf::f('db_server'), + Pluf::f('db_database'), + Pluf::f('db_login'), + Pluf::f('db_password'), + Pluf::f('db_table_prefix'), + Pluf::f('debug'), + Pluf::f('db_version')) + ); + return $GLOBALS['_PX_db']; +}