Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/3/
laggatill.php
skapatabell.php
visa.php
visaB.php
visaC.php
visaD.php
visaE.php
skapatabell.php
53 lines ASCII Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<?php
include('../dbconnection.php');
try {
// sql to create table
$sql = "CREATE TABLE garage (
garageid int(2) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
$sql = "INSERT INTO garage(id, name)";
$stmt = $dbconn->prepare($sql);
$data = array('1', 'red');
$sql =
"CREATE TABLE owner(
ownerid int(2) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
$sql =
"CREATE TABLE car(
carid int(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
regnr varchar(6) NOT NULL,
color varchar(12) NOT NULL,
garage int(2) NOT NULL,
owner int(2) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
// use exec() because no results are returned
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
<a href="../ovn_sql3.php">Tillbaks till meny</a>
</body>
</html>