I am trying to take a variable passed from another page and use it in a PDO query. The variable is the date the record was added and I’m trying to return all the newer records. Do I use $_POST for this in PDO?
<?php
require_once('globals.php');
$date_added = $_POST['date_added'];
$sth = $dbh->prepare("SELECT * FROM games WHERE date_added > $date_added");
$sth->execute();
/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>
You need to actually establish a connection to the database by creating a new PDO object into
$dbh. The code below assumes a database user and password as$dbusername, $dbpasswordand database named$nameofdb.$date_addedis replaced in theprepare()call with a parameter:dateadded, then passed via an array to theexecute()call.Please read the documentation on both
PDO::__construct()andPDO::execute()