How to know if SQL table has been updated - php

I have a table in SQL Server. Its data is about call details of Cisco IP-Phones.
I have a script in PHP.
The data of this table updates whenever a new call occurred.
Once the table updated, I want to fetch new data.
How can I know when the table is updated?
It is not in certain time and depends on when a new call is made.
Fields of table are:
1. id
2. WaitingTime(This is the value that I needed)
3. dateTime (It is the date and the time of updating and inserting the new value)

Technically you could write an ON INSERT trigger that could call a PHP script. However, it's not recommended. There is more information regarding this here: Calling a php file by using mysql trigger
A better approach might be to simply run your PHP script in a cron job to poll the database and process any new calls.

Related

Display the database in mysql from datetime= now()

I want to show the updated values via php since the time i login my page not the previous values. How can i do that. Especially, the data will update frequently and i want to update the data table in my page continuously.
You can use nodejs with php to update real time data.
The mysql query LISTEN and NOTIFY along with triggers you can have NOTIFY events fire when certain queries are performed on specific tables with nodejs.
This links may helpful.
http://nodejs.org/
http://bjorngylling.com/2011-04-13/postgres-listen-notify-with-node-js.html

How to make query after database trigger updates a column?

I have a sequence of insert, after insert trigger update, and query operations and my problem is that the data received from the query does not reflect the updates performed by the trigger (even though the data in the database is indeed updated).
I'm using PHP, PostgreSQL and Propel 1.6 ORM (although this problem might be database and ORM agnostic).
I have the following sequence:
Use AJAX to insert a new row (a vote) in the "book_vote" table (with columns: 'book_id', 'book_score', 'voter_id').
Have a PostgreSQL after insert trigger to update the corresponding book "vote_count" and "average_score" columns in the "book" table.
Make a query to get the new "vote_count" and "average_score" data for the "book" and send that data back to the client with AJAX (to display updated values after the vote).
This all happens within the same PHP session, and my problem is that I do not get the updated "book" values in the AJAX response. It seems like the query is performed before the database trigger is performed. Is there any way to ensure the query happens after the database trigger?
It seems to me that you are doing a save on a Propel object, and you have an external trigger that modifies that row further. You need to be able to tell Propel that the object needs refreshing immediately after the insert/update... and thankfully Propel supports that directly. In your table element in your schema, do this:
<table name="book_vote" reloadOnInsert="true" reloadOnUpdate="true">
You can use either or both of the reload statements, depending on requirements (in your case you'll probably just want the insert one). From there, just rebuild your model and it should work fine.More details here.
Addendum: as per discussion, the issue appears to be that you have already loaded the foreign row that you wish to reload, and as such it is being retrieved from the instance pool rather than the database. You've found that BookPeer::clearInstancePool() solved it for you - great! For bonus points, see if you can remove items from the pool individually - it is probably more efficient to allow the pool to run normally and to remove items one at a time, rather than to clear the pool for a whole table. Let us know if this is possible!
See in ORM documentation how to refetch data after update.
You may have option for column or you have to invoke some method.
Same problem is if you have default value for column and insert.

PHP Do something on MySQL Row Added

I need a way to constantly (in a loop) check if a new MySQL row was added, and if so, do some thing with it, specifically send a notification to users that it pertains to, but I can handle that. I just need to know how to execute code when the number of MySQL rows changes.
You might wish to consider using a MySQL trigger on insert and/or delete:
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-triggers/

Queuing SQL requests PHP

Is it possible to queue client requests for accessing database in MySQL. I am trying to do this for concurrency management. MySQL Locks can be used but somehow I am not able to get the desired outcome.
Effectively what I am trying to do is:
INSERT something in a new row
SELECT a column from that row
Store that value in a variable
The issue comes up when two different clients INSERT at the same time, thus variables for both clients store the value of the last INSERT.
I worked the following alternative, but it failed in a few test runs, and the bug is quite evident:
INSERT
LOCK Table
SELECT
Store
UNLOCK
Thanks!
My best guess is that you have an auto-increment column and want to get its value after inserting a row. One option is to use LAST_INSERT_ID() (details here and here).
If this is not applicable, then please post some more details. What exactly are you trying to do and what queries are being fired?

MYSQL moving information with php

I am wondering if it is possible to automate or by button press to move mysql table information from one table to another table deleting it from the first table and putting it in another table? Using php.
My mysql table is big and the page that adds the information to that table has 70 query's on it which slows the page refresh times. I need to move information from the first table to the second at a certain time of day everyday so that those querys don't have to look through all of my giant 27k row table.
Is this possible?
Also if someone could help me with my comment on this page I would be grateful.
link text
PHP doesn't have a constantly running server you can schedule background tasks with.
If you have access to the server you can set up a cron job (or scheduled task under windows) to run the PHP script for you.
Or (and this isnt so nice) you can put the script on the webserver and call it manually at the appropriate time by entering the URL in your browser.
A 27k row table is small by SQL standards, as long as it is properly indexed.
For instance, if you don't care about data from yesterday, you can add an indexed date column and filter with WHERE myDate > NOW() - INTERVAL 1 DAY, and SQL will automatically restrict the query to the rows younger than 24 hours.
I am wondering if it is possible to automate or by button press to move mysql table information from one table to another table deleting it from the first table and putting it in another table? Using php.
You can initiate it from PHP, but what you ask is effectively MySQL's domain.
It can be accomplished in two statements:
Use an INSERT INTO statement to copy the rows from the old table to the new one
Delete the old table
My preference would be that this occurs in a stored procedure for sake of a transaction and ease of execution (in case you want it initiated by CRON/etc) because it would be easier to call one thing vs a couple or more.
27k is not very big table and MySQL should work ok with that. Do you have all the required indexes? Did you used EXPLAIN on your slow queries?
As for the question about moving data from one table to another - create a php script that will be run by CRON and will move rows one by one. What's the problem here?

Categories