auto insert query in function table_init()

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

auto insert query in function table_init()

Post by amyat » 2021-10-06 05:47

dear teams,

what wrong with my code

i want to auto insert when go table_view.php
so i go hooks/table.php and i wrote this code

function debit_init(&$options, $memberInfo, &$args) {

$db = db_link();
$db->autocommit(FALSE); // Important
$db->query("INSERT INTO debit (date)
SELECT invoices.date FROM invoices WHERE not exists
(select debit.date from debit where debit.date=date(invoices.date) group by date(invoices.date))
group by date(invoices.date)");

$db->autocommit(TRUE); // Important!

return TRUE;
}

this query was correct when i check in my database mysql
but function _init() is not working
what wrong with my code ?
please help me
i'm trying to get acquainted with appgini code
Last edited by amyat on 2021-10-06 05:55, edited 1 time in total.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: auto insert query in function table_init()

Post by jsetzer » 2021-10-06 05:54

If table name equals "debit" then filename should be hooks/debit.php, not hooks/table.php

Did you check your SQL command in your SQL tool (like phpMyAdmin or Adminer)?

Is there a reason why you are not using AppGini's built-in function sql("...", $error)?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

Re: auto insert query in function table_init()

Post by amyat » 2021-10-06 06:04

hi jsetzer,
thanks for fast reply

filename is hooks/debit.php

sql query is working on my database when test on mysql (xampp database)
first , i need to lean appgini's built-in function
sry
how to write insert query in function _init()

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: auto insert query in function table_init()

Post by onoehring » 2021-10-06 07:05

Him

just an idea.
I have not seen "$db->autocommit(FALSE);" yet.
So you turn off autocommit, and turn it on later on again - ok ... but do you commit your SQL at some point in between?
I can not find any command that looks like you do.
Thus - as you do not commit, no SQL is executed ;-)

Olaf

amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

Re: auto insert query in function table_init()

Post by amyat » 2021-10-06 07:33

thank you appgini team

Insert query is working on calculated file

just i want to auto insert date when another table have this date

no need to go write in ( function _init())
I got what i want

but need reload page sometime
now just i need to hide (add new button,save button,update button)

i like appgini ,i want to request "please update bootstrap3.x to last"

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: auto insert query in function table_init()

Post by jsetzer » 2021-10-07 05:33

amyat wrote:
2021-10-06 06:04
how to write insert query in function _init()

Code: Select all

$sql = "YOUR SQL COMMAND HERE";
$error = null;
sql($sql, $error);
if ($error) die($error);
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply