Skip to content

Instantly share code, notes, and snippets.

@alefra88
Created March 5, 2023 09:34
Show Gist options
  • Save alefra88/672cc7524b0a4cbcbd127a7fc32926bf to your computer and use it in GitHub Desktop.
Save alefra88/672cc7524b0a4cbcbd127a7fc32926bf to your computer and use it in GitHub Desktop.
PDO_
// connect
$dsn = 'mysql:host=nombre_de_servidor;dbname=nombre_de_base_de_datos';
$usuario = 'nombre_de_usuario';
$contraseña = 'contraseña';
try {
$dbh = new PDO($dsn, $usuario, $contraseña);
} catch (PDOException $e) {
echo 'Conexión fallida: ' . $e->getMessage();
}
//consult
$stmt = $dbh->prepare('SELECT * FROM nombre_de_tabla WHERE nombre_de_columna = :valor');
//EXEC AND CONSUMING
$valor = 'algún_valor';
$stmt->bindParam(':valor', $valor);
$stmt->execute();
while ($row = $stmt->fetch()) {
// procesar cada fila de resultado
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment