Created
March 5, 2023 09:34
-
-
Save alefra88/672cc7524b0a4cbcbd127a7fc32926bf to your computer and use it in GitHub Desktop.
PDO_
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
// 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