Created
July 11, 2024 15:12
-
-
Save jeffersonchaves/2e519d2213e386fe3faeb431ced3c3ec 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 | |
$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