Created
July 8, 2013 21:49
-
-
Save pbrewczynski/5952786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $db; | |
$db = new PDO('mysql:host=localhost;dbname=homeTaskList;charset=utf8', 'root', 'databasePHG912'); | |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); | |
if(isset($_GET["action"])) { | |
switch ($_GET["action"]) { | |
case "getData" : getData(); | |
break; | |
case "addData" : addData(); | |
break; | |
} | |
} else { | |
echo "You didn't pass the action"; | |
} | |
function getData (){ | |
$stm = $db->query("SELECT * FROM tasks"); | |
echo $stm->fetchAll(PDO::FETCH_ASSOC); | |
} | |
function addData () { | |
$stm = $db->prepare("INSERT INTO | |
tasks(task, responsible_person, createion_data) VALUES(?, ?, MySQL NOW())"); | |
$stm->execute(array($_POST["taskName"],$_POST["responsiblePerson"])); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment