date is the name of the field in the database (tables in an ecommerce app that I didn’t write). This is code that i got from a kind of tutorial so my full understanding of all of it is dubious.
well here is my full query section
[php]try{
$conn = new PDO(“mysql:host=$servername;dbname=$dbname”, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT orderid, DATE_FORMAT(date, ‘%m/%d/%Y’) as orderdate, email, b_state, s_country, subtotal FROM xcart_orders where date BETWEEN $BeginDate AND $EndDate ");
$stmt->execute();
//set the resulting array to associative
$result = $stmt->SetFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchALL())) as $k=>$v) {
echo $v;
}
}[/php]
When i try it the suggested way I get this error
PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in /home/--------/TGemailaddressreport2.php:69
Stack trace:
#0 {main}
thrown in /home/vintagep/public_html/tvpsecure/TGemailaddressreport2.php on line 69
for the code
[php]try{
$conn = new PDO(“mysql:host=$servername;dbname=$dbname”, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$stmt = $conn->prepare("SELECT orderid, DATE_FORMAT(date, ‘%m/%d/%Y’) as orderdate, email, b_state, s_country, subtotal FROM xcart_orders where date BETWEEN $BeginDate AND $EndDate ");
$sql = “SELECT orderid, DATE_FORMAT(date, ‘%m/%d/%Y’) as orderdate, email, b_state, s_country, subtotal FROM xcart_orders where orderdate :from_date AND :todate”;
$stmt = $db_pdo->prepare($sql);
$stmt->execute(Array(’:from_date’ => $BeginDate, ‘:to_date’ => $EndDate));
//set the resulting array to associative
//$result = $stmt->SetFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchALL())) as $k=>$v) {
echo $v;
}
}
[/php]
I dont have this variable anywhere ,$db_pdo, and that may be the problem