This file contains hidden or 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 | |
class Database { | |
private $host = "localhost"; | |
private $db = "estoque_pecas"; | |
private $user = "root"; | |
private $pass = ""; | |
public $conn; | |
public function conectar() { |
This file contains hidden or 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 | |
// models/Produto.php | |
class Produto { | |
private $conn; | |
private $table = "produtos"; | |
public function __construct($db) { | |
$this->conn = $db; | |
} |
This file contains hidden or 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
CREATE DATABASE crud_php; | |
USE crud_php; | |
CREATE TABLE produtos ( | |
id INT AUTO_INCREMENT PRIMARY KEY, | |
nome VARCHAR(100) NOT NULL, | |
preco DECIMAL(10,2) NOT NULL, | |
imagem VARCHAR(255) NOT NULL | |
); |
This file contains hidden or 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
PORT=3000 | |
DB_HOST=localhost | |
DB_USER=root | |
DB_PASS=suasenha | |
DB_NAME=crud_produtos |
This file contains hidden or 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 | |
// Parâmetros de conexão | |
$host = 'localhost'; // Geralmente 'localhost' ou '127.0.0.1' | |
$usuario = 'root'; // Usuário padrão do MySQL (mude se necessário) | |
$senha = ''; // Senha padrão vazia (mude para a sua) | |
$banco = 'comentarios_db'; | |
// Estabelece a conexão | |
$conexao = mysqli_connect($host, $usuario, $senha, $banco); |
This file contains hidden or 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 | |
// Inclui a conexão | |
include 'conexao.php'; | |
// Processa o formulário se for enviado (método POST) | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
// Pega os dados do formulário (com sanitização básica) | |
$nome = mysqli_real_escape_string($conexao, $_POST['nome']); | |
$comentario = mysqli_real_escape_string($conexao, $_POST['comentario']); | |
$data_postagem = date('Y-m-d H:i:s'); // Data atual para o comentário |
This file contains hidden or 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 | |
// Parâmetros de conexão | |
$dsn = 'mysql:host=localhost;dbname=exemplo_db'; | |
$usuario = 'root'; | |
$senha = ''; | |
try { | |
$pdo = new PDO($dsn, $usuario, $senha); | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
This file contains hidden or 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 | |
// Parâmetros de conexão | |
$host = 'localhost'; | |
$usuario = 'root'; | |
$senha = ''; | |
$banco = 'exemplo_db'; | |
// Conexão | |
$mysqli = new mysqli($host, $usuario, $senha, $banco); | |
if ($mysqli->connect_error) { |
This file contains hidden or 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 | |
// Parâmetros de conexão | |
$host = 'localhost'; | |
$usuario = 'root'; | |
$senha = ''; | |
$banco = 'exemplo_db'; | |
// Conexão | |
$conexao = mysqli_connect($host, $usuario, $senha, $banco); | |
if (!$conexao) { |
This file contains hidden or 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
/* Estilos gerais */ | |
body { | |
font-family: Arial, sans-serif; | |
} | |
.container { | |
max-width: 800px; | |
} | |
/* Centralizar botões no footer do modal */ |
NewerOlder