简体   繁体   中英

Caching Queries / Temp Tables for PHP and MySQL

I have a class that handles user registration. There are two main steps: inserting users into a mysql table, and then sending a confirmation e-mail if the insert is successful.

Is there any way that I can...I don't know...sort of cache the first step so that data is not inserted if the the function that handles sending the e-mail fails?

I can check to see if sendmail is enabled on the server, and if not then not even perform the query. I think that would work most of the time, but I also want to catch the times when sendmail is enabled but there's just some error with sending the e-mail.

I though of inserting all data into a temp table, and if the mail send is successful copying the row into the permanent table. The problem with this is that I am calling a stored procedure to insert data, and the mail stuff is happening in application code, so as soon as the insert is done, a temp table would autodelete (is that correct?).

I personally do not send emails from the application. Instead I store the email info in a table, use a cron job to send the emails from the table that way I can take appropriate actions.

Either use Dan's solution "LAST_INSERT_ID()" or in case you first INSERT all users and sending out the email later simply cache the ID to its corresponding user email in order to delete the user by its reference:

array('sample@domain.com' => 123);

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM