dooo61733 2012-05-14 22:31
浏览 143

监视mysql表的订单和存储订单历史记录

  1. I have some website when user can click "order" and his order i saved to orders table.
  2. Orders table has 3 fields: id, user_id, book_id.

I need some script which will monitor changes in orders table - if some orders appear it will read them, 'execute', and remove from orders table.

How I can efficently do it? I have never done anything like this before - I thought about some php script which will be executed in some intervals (10-15 secs - it must be fast) and will read the orders table. But then I thought that I have to keep the orders history - and there is second question - should I make second table for orders history or just add field like "completed" to orders table? I ask this two questions at once because they are corelated - maybe when my orders table will contain also completed orders querying it by my script will be unefficient. I am looking for best solution.

I use MySQL 5.0 databse...

---------- edit

I can't use triggers - I have to execute some php script to process the orders when they appear in orders table!

  • 写回答

1条回答 默认 最新

  • dporb84480 2012-05-14 23:02
    关注

    You need a trigger. Something like this will work.

    create trigger newOrderTrigger after insert on order_table for each row
    //you order execution code goes here
    

    See MySQL Trigger documentation. I've also found this tutorial helpful.

    As for you second question, it depends on your requirements. If you need a full audit-able history, you should probably copy the changes into a new table. If you don't, adding an order_status and changing the value from open to complete is less work.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据