<?php
if(isset($_POST["opret"])) {
$db = @mysql_connect("localhost", "root", "") or die ("<b>Fejl ved connect til DB!</b><br />". mysql_error());
$database = "mintest";
$table_name = "tester";
$make = "CREATE DATABASE `". $database ."` DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci";
if(mysql_query($make)) {
mysql_select_db($database, $db) or die ("<b>Fejl ved select af database!</b><br />".mysql_error());
$sql_create = "CREATE TABLE `". table_name ."` (
`ID` bigint(50) NOT NULL auto_increment,
`email` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
)";
echo"Database er oprettet<br>";
if(mysql_query($sql_create)) {
echo"Tabel er oprettet!";
}else{
echo"Fejl ved tabeloprettelse<br>". mysql_error();
}
}else{
echo"Fejl ved database oprettelse!<br>". mysql_error();
}
exit;
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="submit" name="opret" value="opret database og tabel">
</form>
kilde:
http://www.eksperten.dk/spm/628334