PHP - Call to a member function prepare() on null in /home/cmedic/public_html/CMedic/library/Database.php

 
Vista:

Call to a member function prepare() on null in /home/cmedic/public_html/CMedic/library/Database.php

Publicado por ricardo (3 intervenciones) el 14/02/2019 15:52:17
PORQUE TENGO ESE ERROR¡?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
 
class Database {
 
    private $conn;
    private $sql;
    private $result;
 
 
//
    public function conectar() {
        $archivo = LBS . 'confi.ini';
        if (!$ajustes = parse_ini_file($archivo, true))
            throw new Exception('Error no se pudo abrir el  archivo' . $archivo . '.');
 
//
        $controlador = $ajustes['database']['driver'];
        $servidor = $ajustes['database']['host'];
        $puerto = $ajustes['database']['port'];
        $dbname = $ajustes['database']['shema'];
//
//			
//                        $controlador.':host='.$servidor.';'.$dbname.';charset=utf8'.','.$ajustes['database']['username'].','.$ajustes['database']['password'];
//                        
        try {
            $this->conn = new PDO($controlador . ':host=' . $servidor . ';dbname=' . $dbname . ';charset=utf8', $ajustes['database']['username'], $ajustes['database']['password']);
 
 
            return $this->conn;
        } catch (PDOException $e) {
            echo "Error, no se pudo conectar :" . $e->getMessage();
        }
    }
 
    public function cerrar() {
        $this->conn = null;
    }
 
    public function consulta($sql) {
 
        $this->result = $this->conn->prepare($sql);
        return $this->result;
    }
 
    public function lastInsertId() {
        return $this->conn->lastInsertId();
    }
 
}
 
?>



User_model:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function userLogin($usu, $pass) {
 
//echo "modelo";
 
        $conexion = new Database();
 
        $conexion->conectar();
 
        $sql = "SELECT  usuarios.ID_Usuario, NombUsuario, IdentUsuario,AvatarUsuario, CorreoUsuario, TelefonoUsuario, TipoUsuario, FirmaUsuario, LicenciaUsuario FROM usuarios, detalle_usuario WHERE usuarios.ID_Usuario=detalle_usuario.ID_Usuario and UserLogin=:log and UserPassword=:pass and std_Usuario=:std";
 
        $result = $conexion->consulta($sql);
 
        $result->execute(array(':log' => $usu, ':pass' => sha1($pass), ':std' => 'Activo'));
 
 
 
        return $resultado = $result->fetchAll(PDO::FETCH_ASSOC);
 
 
 
        $conexion->cerrar();
}


CONTROLADOR:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public function UserLogin() {
 
 
 
        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
 
            //Variable de tiempo
 
            $_SESSION['time_expired'] = time() + 1800;
 
 
 
            // Create a new CSRF token.
 
            if (!isset($_SESSION['csrf_token'])) {
 
                $_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
            }
 
//            // Check a POST is valid.
//
            if (isset($_SESSION['csrf_token'])) {
 
 
//
//                // POST data is valid.
//
//
//                   var_dump("si entra");
                $usu = $_POST['UserName'];
 
                $pass = $_POST['UserPassword'];
 
 
 
                $result = $this->model->userLogin($usu, $pass);
//                echo "no me venga a ver la cara";
            }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Call to a member function prepare() on null in /home/cmedic/public_html/CMedic/library/Database.php

Publicado por ricardo (3 intervenciones) el 14/02/2019 21:52:30
la verdad no se porque no puede ingresar a la pagina principal
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar