I have write a query in mysql and it is running in phpmyadmin, but in PHP it giving me error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select docno, docdate, doctype, narration, drcr, (case when drcr = 'Dr' then amo' at line 2
My Query is in PHP is :
$sql = "set @runtot := 0; select docno, docdate, doctype, narration, drcr, (case when drcr = 'Dr'
then amount else 0 end) as debit, (case when drcr = 'Cr' then amount else 0 end) as
credit, concat(abs((@runtot := @runtot + (case when drcr = 'Dr' then amount else amount*-1
end))), (case when @runtot < 0 then ' Cr' else ' Dr' end) ) as balance from (select docno,
docdate, doctype, narration, amount, drcr from ledger where accode = 1 )as q1";
what is wrong here with php?
You have to use transactions to perform several commands in MySQL. You create a varible first and then execute another command.
Using just single function mysqli_query
you can perform only one command and commands are separated by ;
.
When you paste the code into PHPMyAdmin, it will work though as it is still supposed to be a transaction.
You can read more about transactions .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.