Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/exercises/sql-intro/sql-intro3/

create-car.php
createtable.php
insertgarage-owner.php
sql-intro3-index.php
sql-intro3a.php
sql-intro3b.php
sql-intro3c.php
sql-intro3d.php

createtable.php

48 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Create</title>
</head>
<body>
  <?php
  
include ('../../../dbconnection.php');
  try {

    
$sql "CREATE TABLE garage (
    garageid INT(3) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(30) NOT NULL
    )"
;

    
$dbconn->exec($sql);
    
    
$sql "CREATE TABLE owner (
    ownerid INT(3) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(30) NOT NULL
    )"
;
  
    
$dbconn->exec($sql);

    
$sql "CREATE TABLE car (
    carid INT(3) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    regnr VARCHAR(10) NOT NULL,
    color VARCHAR(10) NOT NULL,
    garage INT(3) NOT NULL,
    owner INT(3) NOT NULL
    )"
;
    
    
$dbconn->exec($sql);
    
    echo
"Tabell skapad";

  }
  catch(
PDOException $e){
    echo 
$sql"<br>"$e->getMessage();
  }

  
$dbconn null;
  
?>
</body>
</html>