How can I dynamically listen for database changes? I want to make a shopping website and want to prompt the message "someone bought your product" when someone buys the product, but how can I listen for database changes? Should the regular query database occupy a lot of resources? (1 time per second ). Thank you! ------ solution ------------------ I understand what the landlord means. he means how to dynamically listen to database changes when someone places an order on the current server.
I want to create a shopping website and want to prompt the message "someone bought your product" when someone buys the product. but how can I listen for database changes? Should the regular query database occupy a lot of resources? (1 time/1 s ). Thank you!
------ Solution --------------------
I understand what the landlord meant. he meant that when someone placed an order on the current station, the background staff could immediately obtain the order information instead of refreshing the order.
Currently, I have the following methods,
1. write an email to send the email. when a customer places an order, the email is sent to the administrator's email when inserting the data. it is best to use QQ mail because QQ can remind you. In this way, when someone places an order, they will immediately know that, of course, they can also use text messages (but they need money and there is a delay ).
2. use JS setInterval to check whether the database has changed every three seconds. if there is any, you can make a QQ or TradeManager prompt to prompt the background staff for a new order, that's what I do.
Paste my code:
Var int = setInterval ("clock ()", 20000 );
Function clock (){
$ ("# Call_p" ).html ('
Refreshing screen...');
Var url = "extend/new_dd.php? Cache = "+ Math. random ();
$. Get (url, function (result ){
$ ("# Call_p" ).html (result );
});
}
3. JS setInterval is also used, but it is not used to query the database. when a customer places an order and inserts data, the content in $ _ SESSION [odrer_state] is changed to 1, then we use JS setInterval to get the content every three seconds. if it is set to 1, we will not submit the order to the background personnel, if a background engineer sees the key points and then changes the content of $ _ SESSION [odrer_state] to 0. In this way, database resources are not consumed due to excessive queries.
In fact, there are many methods, depending on how you use the most appropriate. Attach the carrying diagram of this function of my website