Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Aleksandar Veljanov
  5. * Date: 06.11.2016
  6. * Time: 19:21
  7. */
  8. $dns = 'mysql:host=127.0.0.1;dbname=praktikum131088';
  9. $username = 'root';
  10. $password = '';
  11. try {
  12. $pdo = new PDO($dns, $username, $password);
  13. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14. $str = '-- -----------------------------------------------------
  15. -- Table `news`.`news`
  16. -- -----------------------------------------------------
  17. DROP TABLE IF EXISTS `news` ;
  18.  
  19. CREATE TABLE IF NOT EXISTS `news` (
  20. `news_id` INT NOT NULL AUTO_INCREMENT,
  21. `date` DATETIME NOT NULL,
  22. `news_title` VARCHAR(45) NOT NULL,
  23. `full_text` TEXT NOT NULL,
  24. PRIMARY KEY (`news_id`))
  25. ENGINE = InnoDB;
  26.  
  27.  
  28. -- -----------------------------------------------------
  29. -- Table `news`.`comments`
  30. -- -----------------------------------------------------
  31. DROP TABLE IF EXISTS `comments` ;
  32.  
  33. CREATE TABLE IF NOT EXISTS `comments` (
  34. `comment_id` INT NOT NULL AUTO_INCREMENT,
  35. `news_id` INT NOT NULL,
  36. `author` VARCHAR(45) NOT NULL,
  37. `comment` TINYTEXT NOT NULL,
  38. `approved` TINYINT(1) NULL DEFAULT 0,
  39. PRIMARY KEY (`comment_id`),
  40. INDEX `nid_idx` (`news_id` ASC),
  41. CONSTRAINT `news_id`
  42. FOREIGN KEY (`news_id`)
  43. REFERENCES `news` (`news_id`)
  44. ON DELETE CASCADE
  45. ON UPDATE CASCADE)
  46. ENGINE = InnoDB;
  47.  
  48.  
  49. SET SQL_MODE=@OLD_SQL_MODE;
  50. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  51. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  52.  
  53. ';
  54. $ps = $pdo->query($str);
  55. $ps->setFetchMode(PDO::FETCH_ASSOC);
  56. }
  57. catch (PDOException $exception){
  58. die("Could not connect to the database :" . $exception->getMessage());
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement