Advertisement
sanjiisan

Untitled

Apr 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $user = "root";
  5. $pass = "coderslab";
  6. $db = "ex_1";
  7.  
  8. try {
  9. $conn = new PDO(
  10. "mysql:host=$host;dbname=$db;charset=UTF8",
  11. $user,
  12. $pass,
  13. [
  14. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  15. ]
  16. );
  17.  
  18. $sql = "
  19. CREATE TABLE student( id int AUTO_INCREMENT, name varchar(20), number int, PRIMARY KEY(id));
  20. ";
  21.  
  22.  
  23. $res = $conn->query($sql);
  24. if($res){
  25. echo 'Działa!';
  26. }else{
  27. echo 'Nie działa!';
  28. }
  29.  
  30. } catch (PDOException $e) {
  31. echo $e->getMessage();
  32. }
  33.  
  34. echo("Polaczenie udane.");
  35. $conn = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement