示例#1
0
                    $ps->execute(array($editora->nome(), $editora->id()));
                } catch (PDOException $e) {
                    echo 'Erro ao alterar os dados: ' . $e->getMessage();
                }
            } else {
                $editora = new Editora($_POST['id'], $_POST['nome']);
                $ps = $pdo->prepare('INSERT INTO colecaodeeditorasembdr(nome) VALUES(?)');
                try {
                    $ps->execute(array($editora->nome()));
                } catch (PDOException $e) {
                    echo 'Erro ao inserir os dados: ' . $e->getMessage();
                }
            }
            header('Location: editora-lista.php');
        } else {
            $editora = new Editora();
        }
    }
}
?>
	
		<form id="f" name="f" action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="post" >
			<input type='hidden' id='id' name='id' value='<?php 
echo $editora->id();
?>
' /><br />
			<label for="nome">Nome: </label>
			<input type="text" id="nome" name="nome" value='<?php 
示例#2
0
<?php

header('Content-Type: text/html; charset=UTF-8');
require_once 'editora.php';
$pdo = null;
try {
    $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
    $pdo = new PDO('mysql:dbname=editora;hostname=localhost', 'root', '', $options);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Falha ao conectar: ' . $e->getMessage();
}
if (isset($_GET['id'])) {
    $editora = new Editora($_GET['id']);
    $ps = $pdo->prepare('DELETE FROM colecaodeeditorasembdr WHERE id=?');
    try {
        $ps->execute(array($editora->id()));
    } catch (PDOException $e) {
        echo 'Erro ao alterar os dados: ' . $e->getMessage();
    }
    header('Location: editora-lista.php');
}