Skip to content

Instantly share code, notes, and snippets.

@pbrewczynski
Created July 8, 2013 21:49
Show Gist options
  • Save pbrewczynski/5952786 to your computer and use it in GitHub Desktop.
Save pbrewczynski/5952786 to your computer and use it in GitHub Desktop.
<?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