Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("DB_HOST", "localhost");
- define("DB_USER", "root");
- define("DB_PW", "");
- define("DB_DATABASE", "test");
- class MySQL{
- private $conexion;
- private $total_consultas;
- private $interno;
- public function __construct(){
- if(!isset($this->conexion)){
- $this->conexion = (mysql_connect(DB_HOST,DB_USER,DB_PW)) or die(mysql_error());
- mysql_select_db(DB_DATABASE,$this->conexion) or die(mysql_error());
- }
- }
- public function consulta($consulta, $interno){
- $resultado = mysql_query($consulta,$this->conexion);
- if(!$resultado){
- echo 'MySQL Error: ' . mysql_error();
- exit;
- }
- if ($interno != 1) {
- $this->sumar_consultas();
- }
- return $resultado;
- }
- public function fetch_array($consulta){
- return mysql_fetch_array($consulta);
- }
- public function fetch_object($consulta){
- return mysql_fetch_object($consulta);
- }
- public function num_rows($consulta){
- return mysql_num_rows($consulta);
- }
- public function getTotalConsultas(){
- $consulta = $this->consulta('SELECT total FROM stats WHERE id="1"',1);
- $r = $this->fetch_array($consulta);
- return "Total consultas: " . $r['total'];
- }
- private function sumar_consultas($inc) {
- $consulta = $this->consulta('SELECT total FROM stats WHERE id="1"',1);
- $r = $this->fetch_array($consulta);
- $sumar = $r['total'] + $inc;
- $this->consulta('UPDATE stats SET total="'.$sumar.'" WHERE id="1"',1);
- }
- function __destruct(){
- @mysql_free_result($this->consulta);
- @mysql_close($this->conexion);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment