<?php
if (!function_exists('mysql_connect')) {
    function mysql_connect($server = null, $username = null, $password = null, $new_link = false) {
        global $conexion;
        if (!isset($conexion)) {
            $mysql_server = 'localhost';
            $mysql_login = 'cdleweb_adminga26';
            $mysql_password = 'S1lvestre.@24';
            $mysql_database = 'cdleweb_ga2026';
            $conexion = mysqli_connect($mysql_server, $mysql_login, $mysql_password, $mysql_database);
            if (!$conexion) {
                die("Error de conexión: " . mysqli_connect_error());
            }
            mysqli_set_charset($conexion, "utf8");
        }
        return $conexion;
    }
    
    function mysql_select_db($database, $connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_select_db($connection, $database);
    }
    
    function mysql_query($query, $connection = null) {
        global $conexion;
        if ($connection === null) {
            if (!isset($conexion)) {
                $mysql_server = 'localhost';
                $mysql_login = 'cdleweb_adminga26';
                $mysql_password = 'S1lvestre.@24';
                $mysql_database = 'cdleweb_ga2026';
                $conexion = mysqli_connect($mysql_server, $mysql_login, $mysql_password, $mysql_database);
                if (!$conexion) {
                    die("Error de conexión: " . mysqli_connect_error());
                }
                mysqli_set_charset($conexion, "utf8");
            }
            $connection = $conexion;
        }
        return mysqli_query($connection, $query);
    }
    
    function mysql_fetch_array($result, $result_type = MYSQLI_BOTH) {
        return mysqli_fetch_array($result, $result_type);
    }
    
    function mysql_fetch_row($result) {
        return mysqli_fetch_row($result);
    }
    
    function mysql_fetch_assoc($result) {
        return mysqli_fetch_assoc($result);
    }
    
    function mysql_error($connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_error($connection);
    }
    
    function mysql_real_escape_string($string, $connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_real_escape_string($connection, $string);
    }
    
    function mysql_num_rows($result) {
        return mysqli_num_rows($result);
    }
    
    function mysql_affected_rows($connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_affected_rows($connection);
    }
    
    function mysql_get_server_info($connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_get_server_info($connection);
    }
    
    function mysql_close($connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_close($connection);
    }
    
    function mysql_data_seek($result, $row_number) {
        return mysqli_data_seek($result, $row_number);
    }
    
    function mysql_num_fields($result) {
        return mysqli_num_fields($result);
    }
    
    function mysql_field_name($result, $field_offset) {
        $field = mysqli_fetch_field_direct($result, $field_offset);
        return $field ? $field->name : false;
    }
    
    function mysql_free_result($result) {
        return mysqli_free_result($result);
    }
    
    function mysql_insert_id($connection = null) {
        global $conexion;
        if ($connection === null) {
            $connection = $conexion;
        }
        return mysqli_insert_id($connection);
    }
    
    define('MYSQL_ASSOC', MYSQLI_ASSOC);
    define('MYSQL_NUM', MYSQLI_NUM);
    define('MYSQL_BOTH', MYSQLI_BOTH);
}
?>