-
Notifications
You must be signed in to change notification settings - Fork 0
/
testandoBanco.php
executable file
·50 lines (37 loc) · 1.26 KB
/
testandoBanco.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace CursoPHPOO;
use Conexao;
require_once('Conexao.php');
$conexao = new Conexao();
$nome = "André";
$endereco = "Endereço de teste número 2";
$telefone = "(34)2354-7789";
$sql = "INSERT INTO pessoa (nome, endereco, telefone) VALUES (:nome, :endereco, :telefone)";
$stmte = $conexao->getCon()->prepare($sql);
$stmte->bindParam(":nome", $nome);
$stmte->bindParam(":endereco", $endereco);
$stmte->bindParam(":telefone", $telefone);
if ($stmte === false) {
echo "Falha em preparar statement: (". print_r($this->getCon()->errorInfo()).")\n";
}
$query = $stmte->execute();
if($query === false){
echo "Falha em executar query: \n=======\n";
$arr = $stmte->errorInfo();
print_r($arr);
echo "\n========\n";
} else {
echo "Insert realizado com sucesso!<br><br><br>";
}
$sql = "SELECT * FROM pessoa ORDER BY nome";
$pessoas = $conexao->getCon()->query($sql)->fetchAll();
if (!$pessoas) {
print_r($conexao->getCon()->errorInfo());
}
foreach ($pessoas as $pessoa){
echo "Nome: " . $pessoa["nome"] . "<br>";
echo "Endereço: " . $pessoa["endereco"] . "<br>";
echo "Telefone: " . $pessoa["telefone"] . "<br>";
echo "<hr>";
}
?>