Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/EmirPolito/CRUD-HOTEL-GUEVARINI-Publico/llms.txt

Use this file to discover all available pages before exploring further.

The database connection is managed by the Conexion class defined in php/conexion.php. All PHP files that need database access instantiate this class and call obtenerConexion() to receive a PDO connection object.

The Conexion Class

<?php

class Conexion
{
    private $host = "tu-host";
    private $db_name = "tu-base-de-datos";
    private $username = "tu-usuario";
    private $password = "tu-contraseña";
    public $conn;

    public function obtenerConexion()
    {
        $this->conn = null;
        try {
            $this->conn = new PDO(
                "mysql:host=" . $this->host . ";dbname=" . $this->db_name,
                $this->username,
                $this->password
            );
            $this->conn->exec("set names utf8");
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
        catch (PDOException $exception) {
            echo "Error de conexión: " . $exception->getMessage();
        }

        return $this->conn;
    }
}

Configuration Fields

PropertyDescription
$hostThe database server address. For local development this is typically "localhost".
$db_nameThe name of the MySQL database. Must match the database created when importing the SQL file.
$usernameThe MySQL user that has access to the database.
$passwordThe MySQL user’s password. Often empty for local development setups.

Error Handling

obtenerConexion() sets PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION. This means any failed query or connection problem will throw a PDOException rather than silently returning false, making errors visible and easier to debug. The method also runs set names utf8 immediately after connecting, ensuring special characters (accents, ñ, etc.) are handled correctly throughout the application.
The database name must be hotel_guevarini_publico — this is the name that base_de_datos.sql creates automatically when imported. If you use a different name here, the connection will fail.

Configuration Steps

1

Open php/conexion.php

Locate the file at php/conexion.php in the project root and open it in your editor.
2

Set the host

Replace "tu-host" with your database server address. For XAMPP, WAMP, or Laragon running locally, use "localhost".
private $host = "localhost";
3

Set the database name

Replace "tu-base-de-datos" with the name of the database you imported.
private $db_name = "hotel_guevarini_publico";
4

Set your MySQL credentials

Replace the username and password with those of your MySQL user.
private $username = "root";
private $password = "";
5

Save and verify

Save the file and open the application in your browser. If the connection fails, the error message from PDOException will be printed to the page to help diagnose the problem.

Example: XAMPP Local Setup

For a standard XAMPP installation the default MySQL user is root with an empty password:
private $host = "localhost";
private $db_name = "hotel_guevarini_publico";
private $username = "root";
private $password = "";
Never commit real database credentials to version control. If you push php/conexion.php with a real username and password to a public repository, those credentials will be exposed. Use environment variables or a gitignored config file for production credentials.

Build docs developers (and LLMs) love