Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/03/2013, 14:07
Avatar de JaimeMSE
JaimeMSE
 
Fecha de Ingreso: diciembre-2010
Ubicación: Isla Cristina (Huelva)
Mensajes: 164
Antigüedad: 13 años, 4 meses
Puntos: 7
Problemas con clase Mysqli

Hola,

Estoy creando una clase que gestione los select, drop, update, conexiones y tal de mi proyecto web.

Estoy teniendo problemas al acceder a cualquier contenido de la web.
El error que me aparece es:

Fatal error: Call to a member function fetch_object() on a non-object in C:\Users\JaimeMSE\Dropbox\www\librerias\class_db.p hp on line 34

Y la función select es la siguiente:

Código PHP:
Ver original
  1. function select($select, $nombredb, $where, $limit=null)
  2.     {
  3.         #$this->nombredb = $_SESSION['web_db'].'_'.$this->nombredb;
  4.         $this->nombredb = 'web_1_'.$nombredb;
  5.         $this->select   = $select;
  6.         $this->where    = $where;
  7.         $this->limit    = $limit;
  8.  
  9.         if($limit=null)
  10.         {
  11.             $this->consulta = $this->db->query("SELECT {$this->select} FROM {$this->nombredb} WHERE {$this->where}");
  12.             $this->resultado = $this->db->fetch_object($this->consulta);
  13.             return $this->resultado;
  14.         }
  15.         else
  16.         {
  17.             $this->consulta = $this->db->query("SELECT {$this->select} FROM {$this->nombredb} WHERE {$this->where} LIMIT {$this->limit}");
  18.             $this->resultado = $this->consulta->fetch_object($this->consulta);
  19.             return $this->resultado;
  20.         }
  21.     }

A ella la llamo así (dentro de otra clase):

Código PHP:
Ver original
  1. class Articulos
  2. {
  3.  
  4.     function obtenerArticulo($id_articulo)
  5.     {
  6.         global $db;
  7.  
  8.         if(is_int($id_articulo))
  9.         {
  10.             $this->id_articulo = $db->real_escape($id_articulo);
  11.             $articulos = $db->select("*", "articulos", "id_articulo={$this->id_articulo}");
  12.             return $articulos;
  13.         }
  14.         else
  15.         {
  16.             die('No es un número entero.');
  17.         }
  18.     }
  19. }

Y luego en el controlador tengo:

Código PHP:
Ver original
  1. $articulos = new Articulos();
  2. $articulo = $articulos->obtenerArticulo(1);

Estoy algo atascado, ya que no me estoy muy puesto en POO ni en mysqli.

¿Alguien me puede ayudar y/o orientar un poquito?
Gracias.
__________________
@JaimeMSE - ¡Sígueme!