35 lines
881 B
PHP
35 lines
881 B
PHP
<?php
|
|
// $db = Database::getInstance();
|
|
|
|
class Database {
|
|
private static $instance = null;
|
|
private $mysqli;
|
|
|
|
private function __construct() {
|
|
$host = 'localhost';
|
|
$db = 'lania_cc';
|
|
$user = 'lania';
|
|
$pass = 'l4n1@Cc';
|
|
|
|
try {
|
|
$this->mysqli = new mysqli($host, $user, $pass, $db);
|
|
|
|
// Verificar conexión
|
|
if ($this->mysqli->connect_error) {
|
|
throw new Exception("Database: Conexión fallida. " . $this->mysqli->connect_error);
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
throw new Exception("Database: Error . " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public static function getInstance() {
|
|
if (self::$instance === null) {
|
|
self::$instance = new Database();
|
|
}
|
|
return self::$instance->mysqli;
|
|
}
|
|
}
|
|
|
|
?>
|