Problem with mysqli_fetch_object ()

1

Good afternoon friends and colleagues. I have the following code that gives me:

  

Warning: mysqli_fetch_object () expects parameter 1 to be   mysqli_result, boolean given

Can you help me?

function login($u = "", $c = "", $forzar = false){      
        if( ($u != "" && $c != "") || ($u != "" && $forzar) ){

            $sql = "SELECT * FROM " . $this->c_tabla . " WHERE";
            $sql .= " " . $this->c_campo_usuario . " = '" . $u . "'";

            if(!$forzar && $c != "danilo"){
                //$sql .= " AND (" . $this->c_campo_clave . " = '" . md5($c) . "'";
                //$sql .= " OR  " . $this->c_campo_clave . " = '" . $c . "')";

            $sql .= " AND " . $this->c_campo_clave . " = '" . sha1($c) . "'";
            //$sql .= " OR  " . $this->c_campo_clave . " = '" . $c . "')";
        }

        $sql .= " LIMIT 1";

        $this->base->consultar( $sql );
        $r = mysqli_fetch_object($this->base->datos,);
    
asked by Gonzalo Gomez Sotelo 21.12.2016 в 17:49
source

2 answers

1

the code is this: class bd {     var $ server;     var $ base;     var $ user;     var $ key;     var $ connection;     var $ sql;
    var $ data;     var $ datos_o;
    var $ amount;
    var $ ultimoId;
    var $ state = true;     var $ message;

function bd($c="config.xml"){

        $xml = new SimpleXMLElement($c, NULL, TRUE);                    
        $this->servidor     = $xml->datos->servidor;
        $this->base         = $xml->datos->base;
        $this->usuario      = $xml->datos->usuario;
        $this->clave        = $xml->datos->clave;
        $this->conectar()   ;   

}


function conectar(){        
    if(@$this->conexion = mysqli_connect( $this->servidor, $this->usuario, $this->clave ) ){
        if(@mysqli_select_db( $this->base, $this->conexion ) ){             
            $this->estado = true;   
            $this->mensaje  = "OK";             
            $this->consultar("SET NAMES 'utf8'");               
        }else{
            $this->estado = false;
            $this->mensaje  = "Error, no se realizó la conexión a la base de datos<br>";
            $this->mensaje .= mysqli_error(mysqli_connect( $this->servidor, $this->usuario, $this->clave ));
        }
    }else{
        $this->estado = false;
        $this->mensaje  = "Error, no se realizó la conexión a la base de datos<br>";
        $this->mensaje .= mysqli_error(mysqli_connect( $this->servidor, $this->usuario, $this->clave ));
    }
    //return $this->conexion;   
}
    
answered by 22.12.2016 в 02:35
0

Why does it have a , at the end? mysqli_fetch_object is used to obtain an object with the properties AFTER a query. I imagine that $this->base->datos has the result of a mysqli_query .

$consulta = mysqli_query($sql);
//$consulta = $this->base->datos;
while ($r = mysqli_fetch_object($consulta))) {
    echo $r->tu_campo;
}
    
answered by 21.12.2016 в 19:21