Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/databaser/databaser3/
car.php
createtables.php
databaser3.php
databaser3a.php
databaser3b.php
databaser3c.php
databaser3d.php
databaser3e.php
deletetables.php
garage.php
owner.php
start.php
createtables.php
77 lines ASCII Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<?php
include ('../../../dbconnection.php');
// Skapar garage-tabellen
try {
// sql to create table
$sql = "CREATE TABLE garage (
garageid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
garagename VARCHAR(30) NOT NULL
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
// Skapar owner-tabellen
try {
// sql to create table
$sql = "CREATE TABLE owner (
ownerid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
garagename VARCHAR(30) NOT NULL
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
// Skapar car-tabellen
try {
// sql to create table
$sql = "CREATE TABLE car (
carid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
regnr VARCHAR(30) NOT NULL,
color VARCHAR(30) NOT NULL,
garage int(6) NOT NULL,
owner int(6) NOT NULL
)";
// use exec() because no results are returned
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
</body>
</html>