38 lines
880 B
PHP
Executable File
38 lines
880 B
PHP
Executable File
<?php
|
|
|
|
class Conexion{
|
|
|
|
private static $conexion;
|
|
|
|
public static function abrirConexion(){
|
|
|
|
if(!isset(self::$conexion)){
|
|
try {
|
|
include_once 'config.bd.php';
|
|
self::$conexion = new PDO($DB, $userName, $Password);
|
|
self::$conexion ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
self::$conexion -> exec('SET CHARACTER SET utf8');
|
|
|
|
} catch (PDOException $e) {
|
|
echo 'Falló la conexión: ' . $e->getMessage();
|
|
die();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public static function cerrarConexion(){
|
|
if(isset(self::$conexion)){
|
|
self::$conexion = null;
|
|
}
|
|
}
|
|
|
|
public static function obtenerConexion(){
|
|
return self::$conexion;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|