I am trying to create an intermediate class that will register requests in an array along with their runtime. Everything is in order and everything works perfectly. But autocomplete doesn't work when I try to access an intermediate class. How to make autocomplete work. I am using Netbeans.
An intermediate class name is a model.
From my application, I have a class called Users that extends the model.
class Users extends Model { function __construct() { parent::__construct(); $stmt = $this->prepare('SELECT * FROM users WHERE id=? '); $stmt->bindValue(1, 1);
The My Model class is as follows.
class Model extends PDO { public static $log = array(); private $query_cache = array(); public function __construct() { parent::__construct( "mysql:dbname=".MYSQL_DB.";host=".MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD ); } public function query($query) { $time = ""; $query = mysql_real_escape_string(preg_replace( '/\s+/', ' ', $query )); if (key_exists($query,$this->query_cache) && is_object($this->query_cache[$query])) { $result = $this->query_cache[$query]; } else { $start = microtime(true); $result = parent::query($query); $time = microtime(true) - $start; $this->query_cache[$query] = $result; Logger::$logText['DATABASE'][] = array( 'QUERY' => $query, 'TIME' => number_format($time,4) ); } return $result; } public function prepare($query) { return new LoggedPDOStatement(parent::prepare($query)); } }
My LoggedPDOStatement looks like this.
class LoggedPDOStatement { private $statement; public function __construct(PDOStatement $statement) { $this->statement = $statement; } public function execute() { $start = microtime(true); $result = $this->statement->execute(); $time = microtime(true) - $start; Model::$log[] = array( 'query' => '[PS] ' . $this->statement->queryString, 'time' => round($time * 1000, 3) ); return $result; } public function __call($function_name, $parameters) { return call_user_func_array( array($this->statement, $function_name), $parameters ); } }
Do they have a better way to do this?
source share