Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/08/2013, 10:37
Avatar de j_silk_h
j_silk_h
 
Fecha de Ingreso: julio-2010
Mensajes: 54
Antigüedad: 13 años, 9 meses
Puntos: 6
Pregunta POO PHP y mysqli solo corre en navegador Opera

Me sucede esto:
Según yo estaba trabajando bastante bien en POO+mysql probando mis códigos en solo en Opera, pero cuando me da curiosidad por correrlo en Chrome no me funciona, lo probé en IE10 y me paso lo mismo, Safari igual, firefox no lo tengo así que no se, pero en Opera todo anda de mil maravillas, esto sucede? Digo, el PHP es el mismo no? Se que varia en HTML, CSS y en ciertos casos JavaScript, aquí les dejo una muestra del código como información adicional:

Código PHP:
    public function ejecutar($sql){
        
$this->result $this->conex->query($sql);
    }
    
    public function 
getTotalRegistros(){
        
print_r($this->result->num_rows);
        return(
$this->result->num_rows);//En opera devuelve (1) es correcto pues solo tengo 1 reg en mi DB, pero en chrome y demas devuelve (0)
    
}
    
    public function 
getRegistro($campobd){
        if(
$campobd=="*"){
            return(
$this->result->fetch_array(MYSQLI_ASSOC));
        }else{
            
$array $this->result->fetch_array(MYSQLI_ASSOC);
            return(
$array[$campobd]);
        }
    } 
Esta es la función donde creo mi objeto

Código PHP:
function getUbicacionCliente(){
    
    
$ip $_SERVER["REMOTE_ADDR"];
    
$bd Db::getInstance();
    
$bd->ejecutar("SELECT * FROM maquinas_ubicaciones where ip = '".$ip."' ");

        
$bd->getTotalRegistros();//devuelve 0 en otros navegadores (incorrecto)

    
if($bd->getTotalRegistros()>1){
        echo 
"Direccion IP comprometida";
    }else{
        
//header("Location://".$bd->getRegistro("url")); esto solo funciona en Opera tambien
    
}

Aqui les dejo la clase y todo completo por si necesitan mas información

Código PHP:
<?php
session_start
();
date_default_timezone_set("America/Caracas");

class 
Conf{
    private 
$_user;
    private 
$_password;
    private 
$_host;
    private 
$_database;
    
    static 
$_instance;
    
    private function 
__construct(){
        require(
"config.php");
        
$this->_user=$user;
        
$this->_password=$password;
        
$this->_host=$host;
        
$this->_database=$db;
    }
    
    private function 
__clone(){
    }
    
    public static function 
getInstance(){
        if(!(
self::$_instance instanceof self)){
            
self::$_instance = new self;
        }
        return 
self::$_instance;
    }
    
    public function 
getUserDB(){
        
$var $this->_user;
        return 
$var;
    }
    
    public function 
getHostDB(){
        
$var $this->_host;
        return 
$var;
    }
    
    public function 
getPassDB(){
        
$var $this->_password;
        return 
$var;
    }
    
    public function 
getDB(){
        
$var $this->_database;
        return 
$var;
    }
}

class 
Db{
    private 
$servidor;
    private 
$usuario;
    private 
$password;
    private 
$database;
    private 
$conex;
    private 
$result;
    
    static 
$_instance;
    
    private function 
setConexion(){
        
$conf Conf::getInstance();
        
$this->servidor=$conf->getHostDB();
        
$this->database=$conf->getDB();
        
$this->usuario=$conf->getUserDB();
        
$this->password=$conf->getPassDB();
    }
    
    private function 
__construct(){
        
$this->setConexion();
        
        try{
            
$this->conex = new mysqli($this->servidor$this->usuario$this->password$this->database);
        }catch(
Exception $e){
            echo 
$e->getMessage();
        }
    }
    
    public static function 
getInstance(){
        if(!(
self::$_instance instanceof self)){
            
self::$_instance = new self();
        }
        return 
self::$_instance;
    }
    
    public function 
ejecutar($sql){
        
$this->result $this->conex->query($sql);
    }
    
    public function 
getTotalRegistros(){
        
print_r($this->result->num_rows);
        return(
$this->result->num_rows);
    }
    
    public function 
getRegistro($campobd){
        if(
$campobd=="*"){
            return(
$this->result->fetch_array(MYSQLI_ASSOC));
        }else{
            
$array $this->result->fetch_array(MYSQLI_ASSOC);
            return(
$array[$campobd]);
        }
    }
}

function 
getUbicacionCliente(){
    
    
$ip $_SERVER["REMOTE_ADDR"];
    
$bd Db::getInstance();
    
$bd->ejecutar("SELECT * FROM maquinas_ubicaciones where ip = '".$ip."' ");

    if(
$bd->getTotalRegistros()>1){
        echo 
"Direccion IP comprometida";
    }else{
        
//header("Location://".$bd->getRegistro("url"));
    
}
}

?>
:
__________________
!Si se puede imaginar se puede programar!