Page 1 of 1

Insert data in custom table

Posted: Mon Sep 12, 2016 7:42 am
by Anuradha
Hello all,
We are creating process where data has to save in custom tables.So how can we get last inserted id of 1st insert query ,and insert it in 2nd insert query in 2nd table. How it is possible using executeQuery() of processmake. Can we use mysqli_connect(), mysqli_query() and mysqli_insert_id() in trigger.

Re: Insert data in custom table

Posted: Mon Sep 12, 2016 2:46 pm
by amosbatto
If your tables are PM tables then use executeQuery(). See examples in the wiki. If tables are in an external database, then Create a database connection to the database holding the table. Then add a trigger which calls executeQuery() and use the ID of the database connection as the second parameter in the function.

Re: Insert data in custom table

Posted: Tue Sep 13, 2016 12:03 am
by Anuradha
Thanks for reply.But cant we create table other than PM table ,I want the last inserted id of record in trigger.

Re: Insert data in custom table

Posted: Sun Feb 26, 2017 11:02 pm
by chieunh
you can use mysqli_connect(), mysqli_query() and mysqli_insert_id() in trigger.
Ex:
$con=mysqli_connect($host,$user,$passwd,$dbname);
// Check connection
if (mysqli_connect_errno())
{
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
...
$sqlQuery = "......";
if(!mysqli_query($con,$sqlQuery )){
die("Error xxx");
}
mysqli_close($con);


$appID = @@APPLICATION;
$appNumber = @@APP_NUMBER;

In your custom tables, you should use appID or appNumber is primary key.

Re: Insert data in custom table

Posted: Tue Apr 04, 2017 1:54 pm
by mk8800
it's too late and it's a ugly way but this is my way:
Code: Select all
$insertCount= executeQuery("INSERT INTO mytable (column) values('value')");
$result = executeQuery("select LAST_INSERT_ID() L");
$newId=($result[1]['L']);
And Closa Please improve data model and add features like this, you are so far behind from common php frameworks.

Re: Insert data in custom table

Posted: Tue Apr 04, 2017 2:50 pm
by amosbatto
mk8800 wrote:And Closa Please improve data model and add features like this, you are so far behind from common php frameworks.
Please file a bug report about it a http://bugs.processmaker.com and suggest how to improve PM. The developers don't read this forum.