Create/Drop Databases
2003-02-17 00:19:07
Category: php:database
Description: Creates and drops a database from mysql.
Author: detour
Viewed: 2736
Rating: (15 votes)


<?php
  // listdbproc.php by detour@metalshell.com
  //
  // Creates and drops a database from mysql.
  //
  // http://www.metalshell.com/
  //
 
 
  $dbuser = "user";
  $dbpass = "pass";
  $dbhost = "localhost";
 
  echo('<html><head><title>Create Database</title></head><body>');
  echo('<font face="arial" style="font-weight:bold">');
 
  $dbid = mysql_connect($dbhost, $dbuser, $dbpass) or die("Error Connecting");
 
  // Create the database.
  if (mysql_create_db("metal-newdb")) {
    echo('Database created.<br>');
    echo('Now attempting to remove database...<br>');
 
    // Drop the newly created database.
    if(mysql_drop_db("metal-newdb")) {
      echo('Database removed.');
    } else {
      echo('Error: ' . mysql_error());
    }
  } else {
    echo('Error: ' . mysql_error());
  }
 
  mysql_close($dbid);
 
  echo('</body></html>');
 
?>