Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/exercises/mysql-intro_1/

createtable.php
dbconnection.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertposts.php
mysql-main.php
selectposts.php
updateposts.php

createtable.php

40 lines ASCII Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Create</title>
</head>

<body>
    <?php
    
include('dbconnection.php');
    
/**
     * @var PDO $dbconn
     * */
    
try {

        
// sql to create table
        
$sql "CREATE TABLE friend (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    phone_number VARCHAR(10) NOT NULL,
    e_mail VARCHAR(100) 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>