<?php
    global $username;
    global $password;
    global $hostname;
    global $base;
    
    global $conn;
    
    
    $username = "haztuapp_seccem";
    $password = "seccem_1";
    $base = "haztuapp_seccem";
    $hostname = "localhost";
    

    
    function baseConectada() {
        global $conn;
        return $conn;
    }
    
    function conectaBase() {
        if (! baseConectada()) {
            global $conn;
            global $hostname, $username, $password, $base;
            $conn = mysqli_connect($hostname, $username, $password, $base);
            //ejecutaQuery ('SET time_zone = "-05:00"');
        }
    }
    
    function ejecutaQuery($sql){
        global $conn;
        conectaBase();
        if(baseConectada())
        {
            $res = mysqli_query ($conn, $sql);
            if ($res)
                return $res;
            else
                echo "hubo un error en la consulta: $sql<br>" . mysqli_error($conn) . "<br>";
        }
    }
    
    function lastID() {
        global $conn;
        conectaBase();
        return mysqli_insert_id ($conn);
    }
    
    function escape($cadena){
        global $conn;
        conectaBase();
        return mysqli_real_escape_string ($conn, $cadena);
    }
    
    function cierraBase() {
        global $conn;
        if (baseConectada())
        {
            mysqli_close($conn);
        }
    }
?>
