-
Notifications
You must be signed in to change notification settings - Fork 0
/
criarDB.php
80 lines (50 loc) · 1.99 KB
/
criarDB.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html>
<header>
<link rel="stylesheet" href="estilo/justified-nav.css">
<link rel="stylesheet" href="bootstrap-4.6.2-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="style/style.css">
</header>
<?php
//Variaveis para conectar no banco
$servidor_db ="localhost";
$usuario_db="root";
$senha_db=""; //No banco local a senha e vazia, mas se o seu tem senha edicione nesse variavel
//Conectando com o banco de dados
$conexao = new mysqli($servidor_db,$usuario_db,$senha_db);
if ($conexao->connect_error){
die("Conexão falhou: ". $conexao->connect_error);
}
echo "<div class='alert alert-info' role='alert'> Conectado com sucesso no no Mysql.</div>";
//Criar o banco de dados
$nomeDoBanco = "viagens_db";
$sql = "CREATE DATABASE IF NOT EXISTS " . $nomeDoBanco;
if ($conexao->query($sql) === TRUE){
echo "<div class='alert alert-success' role='alert'> Banco de dados 'viagens_db' foi criado com sucesso.</div>";
}
else{
echo "Erro ao criar o banco de dados" .$conexao->error;
}
//Comando para criar tabelas no bando de dados
$sql = "
CREATE TABLE IF NOT EXISTS $nomeDoBanco.cadastro (
id INT(6) AUTO_INCREMENT PRIMARY KEY,
nome VARCHAR(250) NOT NULL,
email VARCHAR(250) NOT NULL,
)
";
if ($conexao->query($sql) === TRUE){
// echo "<h2>Tabela criada com sucesso.</h2>";
echo "<div class='alert alert-success' role='alert'>
<h3> 1) Conexão com banco de dados.✅</h3>
<h3> 2) Criação do banco de dados.✅</h3>
<h3> 3) Criação de tabelas.✅</h3>
<hr>
<h5>Seu banco foi configurado com sucesso. 😀<br> Tudo pronto para cadastrar o seus pacotes de viagem.</h5>
<button type='button' class='btn btn-primary' ><a href='cadastroPacotes.html'style='color:white;'>Cadastrar pacote de viagem</a></button>
</div>";
}
else {
echo "<h2>Erro ao criar a tabela:</h2>" . $conexao->error;
}
?>
</html>