Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dbname = "test";
- $dbhost = "localhost";
- $dbuser = "root";
- $dbpass = "";
- try{
- $db = new PDO( "mysql:host=$dbhost; dbname=$dbname; charset=utf8", "$dbuser", "$dbpass");
- } catch(Exception $e){
- echo "Problem with the connection to database";
- }
- if(!$db->query('SELECT 1 FROM news LIMIT 1')){
- $sql ="CREATE table news(
- id INT( 11 ) AUTO_INCREMENT PRIMARY KEY,
- title TEXT NOT NULL,
- date VARCHAR( 255 ) NOT NULL,
- text TEXT NOT NULL);" ;
- $db->exec($sql);
- }
- $response = NULL;
- include './Router.php';
- $router = new Router($db);
- if($_SERVER['REQUEST_METHOD']=='GET'){
- $response = $router->map('GET', $_GET['id']);
- }else if($_SERVER['REQUEST_METHOD']=='POST'){
- $id = isset($_POST['id']) ? $_POST['id'] : NULL ;
- $title = isset($_POST['title']) ? $_POST['title'] : NULL ;
- $text = isset($_POST['text']) ? $_POST['text'] : NULL ;
- $date = isset($_POST['date']) ? $_POST['date'] : NULL ;
- $response = $router->map('POST', $id, $title, $date, $text);
- }else if($_SERVER['REQUEST_METHOD']=='DELETE'){
- $id = $_POST['id'];
- $response = $router->map('DELETE', $id);
- }
- echo $response;
- exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement