Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connect to MySQL
- // 1. Create a database conexao
- $conexao = mysqli_connect('localhost','root','');
- if (!$conexao) {
- die("Database conexao failed");
- }
- // 2. Select a database to use
- $db_selected = mysqli_select_db($conexao, 'loja');
- if (!$db_selected) {
- // If we couldn't, then it either doesn't exist, or we can't see it.
- $queryDB = 'CREATE DATABASE loja';
- if (mysqli_query($queryDB, $conexao)) {
- echo "Database loja created successfully\n";
- } else {
- echo 'Error creating database: ' . mysql_error() . "\n";
- }
- }
- $queryProdutos = "SELECT * FROM produtos";
- $testaTabelaProdutos = mysqli_query($conexao, $queryProdutos);
- function criaTabelaProdutos(){
- $queryProdutos = "CREATE TABLE produtos (ID int AUTO_INCREMENT PRIMARY KEY,nome varchar(255) NOT NULL)";
- return $queryProdutos;
- }
- if (empty($testaTabelaProdutos)) {
- criaTabelaProdutos();
- if ($testaTabelaProdutos) {
- echo "tabela produtos criada com sucesso.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement