php to run depending on the entry on database

Can I run my php script whenever I see an entry in the database? In other word, can I trigger my php script to run based on the entry in a table?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How about switching it so that the php script is always run, and the first thing it does is mysql_connect and mysql_query to check for a particular entry in the db.  Then, proceed only if mysql_num_rows is >0, i.e. if it is =0, then just exit from the script, e.g. die().
edyonlineAuthor Commented:
how can I make the php script to always run without timing out?
Sudaraka WijesingheWeb Application ProgrammerCommented:
Way to go is create a UDF (User Defined Function) that calls and external script, and call the UDF from insert trigger on the table you want.
I have only done this using SqlServer, but it seem to be possible with MySql also, details are sketchy though.

Here are some references:,76676
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Ajax periodical updater. That is I think you need. In regular time intervals Ajax script call php file that check database table for new data, based on time added new content.

You need also database table that will update time for every Ajax script call. So in every next call you check that table based on timestamp.

select * from ....where time > form last Ajax script last access  time.

I think that Ajax Periodical Updater is solution.

edyonlineAuthor Commented:
I thought ajax is client side, no? how can i execute the php without any browser open to run the ajax?
If you need some job to be done use CRON JOBS.
Ray PaseurCommented:
This part is not clear to me: "whenever I see an entry in the database?"

How will you "see" an entry, if not by running a script?  What will the entry look like?  Who will put it in your data base?  What would you like to make happen when such an entry appears?  Armed with a few more specifics we may be able to suggest a practical solution.  Thanks, ~Ray
edyonlineAuthor Commented:
what i'm trying to accomplish is to implement paypal adaptive payment. This newest paypal api allows one to use API call to check payment status and hence completely remove the dependency on paypal IPN.

As soon as transaction is made, a new row is inserted with status unpaid. Now, without relying on IPN how can I monitor my table to check with paypal api as soon as the pending payment row is inserted. I need this script to keep retrying every 5 seconds.

Do you have any better idea on how to accomplish this?
Sudaraka WijesingheWeb Application ProgrammerCommented:
Well as far as I know, Paypal send you the payment notification via HTTP POST which you have to capture and handle in your own script.
Isn't that the same with this new API? Does it directly update you DB?
Infinite loop guess. Means After you insert in database status unpaid with script add infinite loop that will end when status change to paid.

let's say:
insert in database unpaid:

insert into some_table some column unpaid ......

//define number of checks
$check =($daysx24x60x60)/ 5;

//$check =($days x 24hours x 60minutes x 60seconds)/ 5seconds;


//send request to paypall and get response;
$response = 'paypall response';

if($response == 'paid'){
//update database from unpaid  to paid
//send mail that payment is ok 
sleep(5); //or //usleep(round(number of seconds* 1000000));  



Open in new window

Ray PaseurCommented:
Wow, what was wrong with using the IPN?  It has worked without fail for years.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sudaraka WijesingheWeb Application ProgrammerCommented:
I just took a peek at this document about PayPal Adaptive Payment.
It's IPN (Instant Payment Notification) system seems to be same as what PayPal had from before, which means if you setup a script in your server and give it's URL to PayPal when you initiate the transaction, PayPal will send HTTP POST messages to your URL/Script when the transaction state changes. You don't need to dedicate any resources to continuously monitor any database to archive this.
Ray PaseurCommented:
@sudaraka: Bingo!
edyonlineAuthor Commented:
i see now I understand more after reading documentation. IPN in profile != API call adaptive IPN

I was asking this question earlier because the data in IPN profile is not what i was expecting and therefore I was looking for work around by initiating the call. Now that I realize IPN profile and API IPN are 2 different thing, everything started to make sense. thanks everyone
Sudaraka WijesingheWeb Application ProgrammerCommented:
Glad to help. Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.