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 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R