public function query($query) { //secured query with prepare and execute $timestart = microtime(true); $args = func_get_args(); array_shift($args); //first element is not an argument but the query itself, should removed if (is_array(@$args[0])) { $args = $args[0]; } if (MyPDO::$cache_activate && isset(MyPDO::$cache[$query . "::" . serialize($args)])) { //echo "<div class='query'>cache : '$query' <div>"; MyPDO::$nb_cache++; return MyPDO::$cache[$query . "::" . serialize($args)]; } MyPDO::$cache_activate = true; $reponse = parent::prepare($query); $reponse->execute($args); $err = $reponse->errorInfo(); if (@$err[2]) { if (preg_match("/Duplicate entry/", $err[2])) { return -1; } echo $err[2] . '<hr />' . $query . '<hr />'; print_r($args); return -1; } $ret = array(); while ($o = $reponse->fetch()) { array_push($ret, $o); } $reponse->closeCursor(); if (count($ret)) { MyPDO::$cache[$query . "::" . serialize($args)] = $ret; } // on cache que les requete qui retourne des resultat, insert update doit tjrs etre executé $timeend = microtime(true); $time = $timeend - $timestart; $page_load_time = number_format($time, 3); //echo '<div class="query">query: '.$query.' ('.$page_load_time.'sec)</div>'; return $ret; }