Click here to Skip to main content
15,913,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am developing a chat system in php. So whenever user sends message to another user the receiving user's chatbox should get refreshed. I have stored messages in mysql table. So whenever one record get inserted in table i should reload the chatbox. How to do this? Can i use trigger for this?
Posted

Two ways..

1. You can have Output variable in your stored proceedure indicating successful or failure of inserting.

if output variable value successful then the record get inserted. else not inserted.

2. You can use trigger's. This works when row inserted or deleted or updated.

For more see below link..
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html[^]
http://dev.mysql.com/doc/refman/5.0/en/triggers.html[^]
http://www.sitepoint.com/how-to-create-mysql-triggers/[^]
 
Share this answer
 
Here is one example..

SQL
ALTER PROCEDURE dbo.postcomments_sp_global
	@aaa,
	@output varchar(50) output // output variable
	AS
	begin try
	insert into tablename(col1) 
values(@aaa) 
set @output='Record inserted successfully... Thank you..'
print @output
end try
begin catch
set @output=(select error_message() as err)//error message
end catch
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900