Skip to content

Instantly share code, notes, and snippets.

@jeffersonchaves
Created July 11, 2024 15:12
Show Gist options
  • Save jeffersonchaves/2e519d2213e386fe3faeb431ced3c3ec to your computer and use it in GitHub Desktop.
Save jeffersonchaves/2e519d2213e386fe3faeb431ced3c3ec to your computer and use it in GitHub Desktop.
<?php
$usuario = "root";
$senha = "bancodedados";
$url_conexao = "mysql:host=localhost;dbname=db_contatos";
$conexao = new PDO($url_conexao, $usuario, $senha);
$conexao->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$nome = "Souza";
$resultado = $conexao->query("SELECT * FROM contato WHERE nome LIKE '%$nome%'");
$contatos = $resultado->fetchAll(PDO::FETCH_ASSOC);
print_r($contatos);
} catch(PDOException $e){
print ("erro ao executar o comando: " . $e->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment