Page 1 of 1

auto insert query in function table_init()

Posted: 2021-10-06 05:47
by amyat
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

Re: auto insert query in function table_init()

Posted: 2021-10-06 05:54
by jsetzer
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)?

Re: auto insert query in function table_init()

Posted: 2021-10-06 06:04
by amyat
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()

Re: auto insert query in function table_init()

Posted: 2021-10-06 07:05
by onoehring
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

Re: auto insert query in function table_init()

Posted: 2021-10-06 07:33
by amyat
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"

Re: auto insert query in function table_init()

Posted: 2021-10-07 05:33
by jsetzer
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);