Пример #1
0
function delete_movie($id)
{
    $pdo = get_PDO();
    try {
        //Initiate a transaction
        $pdo->beginTransaction();
        $genreDeleteQuery = $pdo->prepare("DELETE FROM `movie_genres` WHERE movie_id = :movie_id");
        $genreDeleteQuery->bindParam(":movie_id", $id, PDO::PARAM_INT);
        if ($genreDeleteQuery->execute()) {
            $movieDeleteQuery = $pdo->prepare("DELETE FROM `movie_data` WHERE id = :movie_id");
            $movieDeleteQuery->bindParam(":movie_id", $id, PDO::PARAM_INT);
            $genreDeleteQuery->execute();
            $commit = true;
        } else {
            $commit = false;
        }
    } catch (PDOException $ex) {
        $commit = false;
    }
    if (!$commit) {
        $pdo->rollback();
    } else {
        $pdo->commit();
        //Return true or something
        return true;
    }
    return false;
}
Пример #2
0
<?php

include '../common.inc.php';
$pdo = get_PDO();
$status = $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);
if ($status) {
    //If we already have a working database with the tables we need then abort this and send the user to the main page
    if (isset($_GET['action'])) {
        switch ($_GET['action']) {
            case 'createGenresTable':
                $queryString = <<<EOL
    CREATE TABLE IF NOT EXISTS `genres` (
    `id` int NOT NULL AUTO_INCREMENT,
  `genre` text NOT NULL,
    PRIMARY key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
EOL;
                break;
            case 'createMovieDataTable':
                $queryString = <<<EOL
    CREATE TABLE IF NOT EXISTS `movie_data` (
    `id` int NOT NULL AUTO_INCREMENT,
  `title` text,
  `release_date` year(4) DEFAULT NULL,
  `score` text DEFAULT NULL,
  `imdb_id` text DEFAULT NULL,
  `image_file_path` text DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
EOL;
                break;