コード例 #1
0
ファイル: categorias.php プロジェクト: EnnioSimoes/crud-pdo
<?php

try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $ex) {
    echo 'Não foi possível conectar ao banco de dados!';
}
require 'CategoriaEntity.php';
require 'CategoriaService.php';
$categorias = new CategoriaEntity();
$categorias->setNome('Jogos');
$service = new CategoriaService($conexao, $categorias);
$categories = $service->listar();
if ($_GET && $_GET['action'] == 'delete') {
    $categorias = new CategoriaEntity();
    $service = new CategoriaService($conexao, $categorias);
    $service->delete($_GET['id']);
    header("Location:http://127.0.0.1:8080/categorias.php");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    </head>
    <body>
コード例 #2
0
<?php

try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $exc) {
    echo $exc->getTraceAsString();
}
if ($_POST) {
    require 'CategoriaEntity.php';
    require 'CategoriaService.php';
    $categoria = new CategoriaEntity();
    $categoria->setNome($_POST['nome']);
    $service = new CategoriaService($conexao, $categoria);
    $categories = $service->insert();
    header("Location:http://127.0.0.1:8080/categorias.php");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    </head>
    <body>
        <div class="row">
            <div class="col-md-3">
                <ul class="nav">
コード例 #3
0
try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $exc) {
    echo $exc->getTraceAsString();
}
require 'CategoriaEntity.php';
require 'CategoriaService.php';
if ($_GET) {
    $categoria = new CategoriaEntity();
    $service = new CategoriaService($conexao, $categoria);
    $categories = $service->find($_GET['id']);
    //    var_dump($categories);
}
if ($_POST) {
    $categoria = new CategoriaEntity();
    $categoria->setNome($_POST['nome'])->setId($_POST['id']);
    $service = new CategoriaService($conexao, $categoria);
    $categories = $service->update($_GET['id']);
    header("Location:http://127.0.0.1:8080/categorias.php");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">