Fatal error: Call to a member function query () on null in

0

I am trying to make a Login using the Vista Controller model (MVC), the database is already created, the problem is when validating a user, whatever the user sends this message.

<?php
class conexion{

  private $conexion;
  private $server = "localhost";
  private $usuario = "root";
  private $pass = "";
  private $db = "login";
  private $user ;
  private $password;

  public function _construct(){

    $this->conexion = new mysqli($this->server, $this->usuario, $this->pass, $this->db);

    if ($this->conexion->connect_errno) {

      die("Fallo al tratar de conectar con MYSQL: (".$this->conexion->connect_errno.")");

    }
  }

  public function cerrar(){
    $this->conexion->close();
  }

  public function login($usuario, $pass){

    $this->user = $usuario;
    $this->password = $pass;

    $query = "select id, nombre, apellido, usuario, password from wisher where usuario = '".$this->user."' and password = '".$this->password."' ";

    $consulta = $this->conexion->query($query); //error linea 34

    if ($row = mysqli_fetch_array($consulta)) {
      # code...

      session_start();

      $_session['id'] = $row['id'];
      $_session['nom'] = $row['nombre'];
      $_session['ape'] = $row['apellido'];

      echo "Has iniciado sesion";

      echo $_session['id'];
      echo $_session['nom'];
      echo $_session['ape'];

    }else {
      echo "usuario o contraseña incorrectos";
    }



  }


}

? >

    
asked by Allan Pacheco 15.05.2017 в 01:31
source

1 answer

1

Did you instantiate class conexion before the query?

$c = new conexion;
$c->login(...);

By convention the classes are Pascal Case. (in this case class Conexion )

    
answered by 15.05.2017 в 02:13