nashashmi
(Anas Hashmi)
1
I try to bind value $item to :item in the SQL query but it is not working.
Can anyone find what I am doing wrong?
$sqlstatement='SELECT ITEM, DESCRIPTION, sumofBID_QTY AS BID_QTY, avgofUNIT_PRICE AS UNIT_PRICE, UNIT '
. 'FROM BID_COST_BY_ITEMS '
. 'WHERE ITEM=":item";'
. 'SELECT `DATE_WRITTEN` AS DATE, LOCATION, IR_NO, QUANTITY AS QTY, PAYMENT '
. 'FROM CONSOLIDATED_TABLE '
. 'WHERE ITEM=":item"'
. 'AND IR_NO<>"0" '
. 'ORDER BY PAYMENT, DATE';
echo
$query = $this->loadData('connection')->createCommand($sqlstatement)->bindValue(':item',$item)->prepare()->text;
softark
(Softark)
2
You can not repeat the same name ‘:item’ for the place holders twice even when they are the same thing.
Use ‘:item1’ and ‘:item2’ instead.
Keith
(Kburton)
3
You can use the same place holders, but you shouldn’t be wrapping them in quotes:
$sqlstatement='SELECT ITEM, DESCRIPTION, sumofBID_QTY AS BID_QTY, avgofUNIT_PRICE AS UNIT_PRICE, UNIT '
. 'FROM BID_COST_BY_ITEMS '
. 'WHERE ITEM=:item;'
. 'SELECT `DATE_WRITTEN` AS DATE, LOCATION, IR_NO, QUANTITY AS QTY, PAYMENT '
. 'FROM CONSOLIDATED_TABLE '
. 'WHERE ITEM=:item'
. 'AND IR_NO<>"0" '
. 'ORDER BY PAYMENT, DATE';
echo
$query = $this->loadData('connection')->createCommand($sqlstatement)->bindValue(':item',$item)->prepare()->text;
softark
(Softark)
4
Oh, I didn’t notice the quotation marks.
And I missed that there are 2 queries here … I believe you can not execute 2 queries at a time.