SQL IN HOOK

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
igimanigi
Posts: 11
Joined: 2016-11-30 18:24

SQL IN HOOK

Post by igimanigi » 2016-12-12 13:51

I am new to appgini but I am a programmer. I have a Billig_Header table and a Billing_Detail table. I want to update a 'Total' field in the header table as i add or update the Amount field in the Detail table. After doing some reading, I have done the following in the after_update and after_insert hooks of the Billing_Detail table but its not working.

sql("UPDATE Billing_Header SET Total=Total+{$data['Amount']} WHERE ID={$data['Billing_ID']}");

What am I doing wrong.
Thanks in advance.

Bertv
Veteran Member
Posts: 65
Joined: 2013-12-11 15:59

Re: SQL IN HOOK

Post by Bertv » 2016-12-13 16:38

Hi,
you forgot the return parameter of the sql-(AppGini)function.

What I always do is split the creation of the sql-string and the execution. After the create of the sql-string I can debug it.
With your update this looks
$sql_string = "UPDATE Billing_Header SET Total=Total+{$data['Amount']} WHERE ID={$data['Billing_ID']}";
$result = sql($sql_string, $eo);
Bert
I am using Appgini 5.75

igimanigi
Posts: 11
Joined: 2016-11-30 18:24

Re: SQL IN HOOK

Post by igimanigi » 2016-12-14 10:54

oh, thanks. it works now.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: SQL IN HOOK

Post by DevGiu » 2016-12-14 15:08

Just to clarify, second parameter of sql() function, is not the return parameter, is an "options" parameter., and is optional, throwing a warning on error log, not sure why this affected your query. If you pass array('silent-errors', true), it ignores any possible errors on screen.
/Giuseppe
Professional Outsourcing Services

Post Reply