Reputation: 8346
If I manually execute the following query replaced with values instead of : , its working but the same query is not returning anything if execute through php...
$sql_check = $dbConnection->prepare("select sum(case when
upper(main_category)=upper(:main_category) and
upper(sub_category1)=upper(:sub_category1) then 1
when upper(main_category)=upper(:main_category) then 1 else 0 end) cnt from dbs.sales;");
$sql_check->execute(array(':main_category' => $main_category,':sub_category1' =>
$sub_category1,':sub_category2' => $sub_category2));
foreach ($sql_check as $row) {
$cnt=$row['cnt'];
echo "cnt ".$cnt."<br>"; //No rows returned upon execution
}//end of for loop
Here :main_category is being used twice
The above query is working fine if i DO NOT use :main_category twice...
Please help me and let me know how to run the query if the same parametrised field is to be used in the query?
Upvotes: 0
Views: 126
Reputation: 157862
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
first to make it work
and
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
would be useful too
Upvotes: 2