-
-
Save parzibyte/bc6d72b57dfaff3db4b61914d78d97b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
CRUD con PostgreSQL y PHP | |
@author parzibyte [parzibyte.me/blog] | |
@date 2019-06-17 | |
================================ | |
Este archivo se encarga de conectar a la base de datos | |
y traer un objeto PDO | |
Recuerda cambiar tus credenciales, y tal vez ponerlas en | |
un archivo env: https://parzibyte.me/blog/2018/06/30/leer-archivo-configuracion-ini-php/ | |
================================ | |
*/ | |
$contraseña = "hunter2"; | |
$usuario = "parzibyte"; | |
$nombreBaseDeDatos = "mascotas"; | |
# Puede ser 127.0.0.1 o el nombre de tu equipo; o la IP de un servidor remoto | |
$rutaServidor = "127.0.0.1"; | |
$puerto = "5432"; | |
try { | |
$base_de_datos = new PDO("pgsql:host=$rutaServidor;port=$puerto;dbname=$nombreBaseDeDatos", $usuario, $contraseña); | |
$base_de_datos->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
} catch (Exception $e) { | |
echo "Ocurrió un error con la base de datos: " . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment