<?php
include "busca_concha.php";

// Privilevios: SELECT, INSERT, UPDATE
// HACER: PONERLE UN POCO DE ONDA PARA QUE SOLO CADA RADIO TENGA ACCESO A SU INFO
$basedato_remote = 'alexis_webrica';
$usuario_remote = 'alexis_webrica';
$contra_remote = '!%)&YFf38&(!&987yns29KLSD873';

function remote_sql_command($sql_command) {
    global $host, $basedato_remote, $usuario_remote, $contra_remote;
    try {
        $mbd = new PDO("mysql:host=$host;dbname=$basedato_remote", $usuario_remote, $contra_remote);
        $statement = $mbd->prepare($sql_command);
        $statement->execute();
        return $statement;

    } catch (PDOException $e) {
        return "¡Error!: " . $e->getMessage();
    }
}

function remote_query($sql_query) {
    $statement = remote_sql_command($sql_query);
    return $statement->fetchAll(PDO::FETCH_ASSOC);
}

function get_or_create($name) {
    $data = remote_query("SELECT * FROM radios WHERE website=$name")[0];
    if (!$data) {
        remote_query("INSERT INTO radios (website) VALUES ('$name')");
        $data = remote_query("SELECT * FROM radios WHERE website='$name'")[0];
    }
    return $data;
}