MySQL Forums
Forum List  »  PHP

MySql after inset trigger not exporting new inserted data into csv file
Posted by: Priyadarshni Sagar
Date: March 07, 2020 11:15PM

I am calling the procedure to export a newly inserted record into the CSV file from MySQL after insert trigger. For dynamic file generation, I wrote a PHP script. The procedure is invoking this PHP script by UDF function, sys_exec. The problem, I am facing here is my trigger is calling procedure before actually inserting data into the database so after every after insert trigger call, I am getting old records in CSV file. Is there any solution to get only new inserted data into CSV file? Here is my after insert trigger, which gives a call to the procedure for exporting CSV file:

BEGIN
call exportFile();
END

exportFile procedure:

BEGIN
DECLARE RESULT INT;
SET RESULT = sys_exec('php C:/export.php');
END

PHP script to generate a new CSV file and write a new inserted record in the file:

$query = " select id from table ";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_row($result)) {
fputcsv($fp, $row);

}

Options: ReplyQuote


Subject
Written By
Posted
MySql after inset trigger not exporting new inserted data into csv file
March 07, 2020 11:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.