1

I want to ask is there a way to track database table using php mysql. I want to do something like i have a table called post. Now when user post some data other user need to view this data. That is latest one need to be view to user on the top. We can do this by refreshing div after every few sec or using ajax. But can we use Trigger. As we know it automatically fires when something is executed. Hence i want to know can we use trigger in PHP code to automatically detect changes in table. And when a new post is available it needs to return the data from database. Please give me a brief description about this. Thank you in advance.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Rohit Dubey
  • 174
  • 1
  • 2
  • 12

2 Answers2

0

The trigger is executed on Mysql Server, not on the PHP one (even if those are both on the same machine).

So, I would say this is not quite possible -- at least not simply.

Still, considering this entry from the MySQL FAQ on Triggers :

23.5.11: Can triggers call an external application through a UDF?

Yes. For example, a trigger could invoke the sys_exec() UDF available at MySQL Forge here: http://forge.mysql.com/projects/project.php?id=211

So, there might be a waty, actually, via an UDF function that would launch the php executable/script ; not that easy, but seems possible ;-)

Read more about it in:

https://stackoverflow.com/a/1467387/3653989

Community
  • 1
  • 1
Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
0

SQL trigger is a database object executed server-side. You want a front-end technique to refresh your data without refreshing the whole page. You can refresh your page using:

<meta http-equiv="refresh" content="5">

With PHP, you can refresh the page using:

header("refresh: 3;");

but no-one would suggest you to use such a method, because your need is refreshing the page, only after a change in your database, and not continuously.

So, if you already use PHP, you need Javascript Push technology: Push, or server push, describes a style of Internet-based communication where the request for a given transaction is initiated by the publisher or central server. (wikipedia)

JavaScript polling, long-polling, real-time techniques, and javascript frameworks such as jquery, node.js, socket.io include a lot of practices that give you this possibility.

Nik Drosakis
  • 2,258
  • 21
  • 30
  • refreshing whole page is not a good idea. Instead i could go for ajax which will load content after every few seconds. I want my application to know automatically that if the count of table is increased it should fetch the datas from database – Rohit Dubey Mar 07 '15 at 14:47