Guest User

Untitled

a guest
Dec 28th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "username";
  4. $password = "password";
  5. $dbname = "myDBPDO";
  6.  
  7. try {
  8.     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9.     // set the PDO error mode to exception
  10.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.  
  12.     // sql to create table
  13.     $sql = "CREATE TABLE MyGuests (
  14.    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  15.    firstname VARCHAR(30) NOT NULL,
  16.    lastname VARCHAR(30) NOT NULL,
  17.    email VARCHAR(50),
  18.    reg_date TIMESTAMP
  19.    )";
  20.  
  21.     // use exec() because no results are returned
  22.     $conn->exec($sql);
  23.     echo "Table MyGuests created successfully";
  24.     }
  25. catch(PDOException $e)
  26.     {
  27.     echo $sql . "<br>" . $e->getMessage();
  28.     }
  29.  
  30. $conn = null;
  31. ?>
Add Comment
Please, Sign In to add comment