Skip to content

Instantly share code, notes, and snippets.

@carlosdcordero
Last active March 8, 2018 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosdcordero/1da415533e193256e99dea27f2a2fa2b to your computer and use it in GitHub Desktop.
Save carlosdcordero/1da415533e193256e99dea27f2a2fa2b to your computer and use it in GitHub Desktop.
<?php
function conectar($nameDB = '', $userDB = '', $passDB = '') {
if ($nameDB !== ''|| $userDB !== ''|| $passDB !== '') {
try {
$link = new PDO (
'mysql:host=localhost;
dbname=' . $nameDB . '',
$userDB,
$passDB
);
} catch (PDOException $e) {
print '¡Error!: ' . $e->getMessage() . '<br/>';
die();
}
} else {
echo '¡Error al conectar!';
}
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment