Reputation: 1384
I am trying to run this SQL Query in PHP PDO:
$stmt = $pdo_conn->prepare("SELECT * from integra_status where type <> :type1 and category1 = :category and (status = :status1 or status = :status2)
UNION
SELECT * from integra_status WHERE type = :type2 and maintenance_fromdate <= :maintenance_fromdate AND maintenance_todate >= :maintenance_todate and category = :category2 order by sequence ASC ");
$stmt->execute(array(':type1' => 'Maintenance', ':category1' => $result["sequence"], ':status1' => 'Open', ':status2' => 'Resolved',
':type2' => 'Maintenance', ':maintenance_fromdate' => 'DATE_ADD(NOW(), INTERVAL 7 DAY)', ':maintenance_todate' => 'DATE_SUB(NOW(), INTERVAL 2 DAY)', ':category2' => $result["sequence"] ));
but I am getting this output:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /home/integra/public_html/service_status/index.php:48 Stack trace: #0 /home/integra/public_html/service_status/index.php(48): PDOStatement->execute(Array) #1 /home/integra/public_html/index.php(124): include('/home/integra/p...') #2 {main} thrown in /home/integra/public_html/service_status/index.php on line 48
Upvotes: 1
Views: 220
Reputation: 80647
You are passing:
':category1' => $result["sequence"]
in your execute statement, while your query reads:
where type <> :type1 and category1 = :category and
Also note that you will not be able to use
':maintenance_fromdate' => 'DATE_ADD(NOW(), INTERVAL 7 DAY)'
as you want to. Use the function directly in your query:
maintenance_fromdate <= DATE_ADD(NOW(), INTERVAL 7 DAY)
Upvotes: 2