Logo  

CS479/579 - Web Programming II

Displaying exercises/e6/solution/newdb.php

<?php
include "config.php";

$myconn->query("DROP TABLE IF EXISTS `messages`")
    or die("query" . $myconn->error);

$myconn->query("
    CREATE TABLE `messages` (
      `id`                INT(10)         UNSIGNED NOT NULL AUTO_INCREMENT,
      `title`     VARCHAR(100)    NOT NULL DEFAULT '',
      `mesg`      TEXT            NOT NULL DEFAULT '',
      `date`      TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP(),
      PRIMARY KEY (`id`),
      INDEX `title` (`title`)
    )
") or die("query" . $myconn->error);

$myconn->query("
    INSERT INTO `messages` (`title`, `mesg`)
      VALUES ('Default', 'This is a default message')
") or die("query" . $myconn->error);

echo "Database initialized!<br>\n";
?>