dongwuwu6104 2014-09-22 11:35
浏览 35
已采纳

当PHP提交更新时,为C ++应用程序调用SQLite触发器

I have a SQLite database populated by a C++ application. I am also working on a web interface to allow different diplays using Javascript and PHP. There will only be one instance of the interface open at any given time but it will be on another machine in the network from the SQLite file and C++ application.

There are a couple fields I would like to be able to update from the interface. I can create a trigger to let the C++ application know when data is changed, but if PHP makes the change, the trigger targets that connection and throws an error (since the callback function is defined in the C++ code). I tried enabling shared cache connections for everything involved but the SQLite trigger still can't cross the applications.

Is there a way to automatically notify the C++ application of changes or will I have to regularly poll the database if we continue using SQLite?

The documentation I've been able to find all suggest the latter, but most of it is either vague or older so I'm hoping there's a workaround I haven't been able to find.

  • 写回答

1条回答 默认 最新

  • dsm42026 2014-09-22 12:04
    关注

    I think that it is simply not possible to execute an own C++ function when PHP updates an SQLite database as PHP is using its internal SQLite library to update the database.

    So unless you want to mess with PHP and recompile with a custom SQLite implementation (which I really recommend against) you're out of luck.

    Alternatives:

    • You could watch the SQLite file itself on the disk, and you can execute your program if that is updated. However, filesystem watching daemons are not really working well with network drives.

    • Polling the database is the safest option - that always works, but might be slow, especially because you might open the same SQLite file from two programs at once.

    Anyway, if you need to access the database from more than one place (PHP program and C++ program) it might be time to use a different database engine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么