Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. $dbname = "test";
  4. $dbhost = "localhost";
  5. $dbuser = "root";
  6. $dbpass = "";
  7.  
  8. try{
  9.  
  10. $db = new PDO( "mysql:host=$dbhost; dbname=$dbname; charset=utf8", "$dbuser", "$dbpass");
  11.  
  12. } catch(Exception $e){
  13.  
  14. echo "Problem with the connection to database";
  15.  
  16. }
  17.  
  18. if(!$db->query('SELECT 1 FROM news LIMIT 1')){
  19.  
  20. $sql ="CREATE table news(
  21. id INT( 11 ) AUTO_INCREMENT PRIMARY KEY,
  22. title TEXT NOT NULL,
  23. date VARCHAR( 255 ) NOT NULL,
  24. text TEXT NOT NULL);" ;
  25.  
  26. $db->exec($sql);
  27.  
  28. }
  29.  
  30. $response = NULL;
  31.  
  32. include './Router.php';
  33.  
  34. $router = new Router($db);
  35.  
  36. if($_SERVER['REQUEST_METHOD']=='GET'){
  37.  
  38. $response = $router->map('GET', $_GET['id']);
  39.  
  40. }else if($_SERVER['REQUEST_METHOD']=='POST'){
  41.  
  42. $id = isset($_POST['id']) ? $_POST['id'] : NULL ;
  43. $title = isset($_POST['title']) ? $_POST['title'] : NULL ;
  44. $text = isset($_POST['text']) ? $_POST['text'] : NULL ;
  45. $date = isset($_POST['date']) ? $_POST['date'] : NULL ;
  46.  
  47. $response = $router->map('POST', $id, $title, $date, $text);
  48.  
  49. }else if($_SERVER['REQUEST_METHOD']=='DELETE'){
  50.  
  51. $id = $_POST['id'];
  52.  
  53. $response = $router->map('DELETE', $id);
  54. }
  55.  
  56. echo $response;
  57.  
  58. exit;
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement