Guest User

Untitled

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