0

I want to write php script to execute sql query every 3 seconds automatically and indefinitely until I stop it. this is my sql query that I want to execute

UPDATE users SET bouquet =
  '["12","10","11","8","9","6","7","5","4","3","2","1"]'

The database name is xtream_iptvpro

Sorry, I am a beginner so I really don't know any thing. Thanks for your help

2 Answers2

1

you have to use any cli or a some other technology to proceed.

for example if it's mysql you can use PHP, java or you can build it using console command.

while true; do echo -n "execute your query here"; sleep 3; done

while true; do mysql -u root -p somedb -e "select * from mytable"; sleep 3; done

This solultion might help you

ieatbytes
  • 516
  • 1
  • 6
  • 13
1

If you periodically "patch" some column of a table, then the columns will have the wrong data for some time. You probably don't want that.

Instead, I think a trigger will be better, since it will "fix" the data on the fly while being inserted/updated. The table won't ever have the wrong data to begin with.

See 24.3.1 Trigger Syntax and Examples.

For example (tweak as necessary):

create table users (id int, bouquet varchar(100));

create trigger fix_data before insert on users 
for each row 
begin
  set NEW.bouquet = '["12","10","11","8","9","6","7","5","4","3","2","1"]';
end;

Then, if you run the following INSERT statements:

insert into users (id, bouquet) values (1, 'Hello');
insert into users (id) values (2);
insert into users (id, bouquet) values (3, null);
insert into users (id, bouquet) values (4,
  '["12","10","11","8","9","6","7","5","4","3","2","1"]');

select * from users;

You get the result:

id  bouquet                                           
--  ----------------------------------------------------
1   ["12","10","11","8","9","6","7","5","4","3","2","1"]
2   ["12","10","11","8","9","6","7","5","4","3","2","1"]
3   ["12","10","11","8","9","6","7","5","4","3","2","1"]
4   ["12","10","11","8","9","6","7","5","4","3","2","1"]
The Impaler
  • 45,731
  • 9
  • 39
  • 76
  • Okay so based on my understanding, I just execute this command in mysql and it will edit any new entry. I use phpmyadmin for my sql databases. – Ahmed Kaicer Feb 23 '20 at 17:37
  • it keeps giving me error from line 4 SQL query: create trigger fix_data before insert on users for each row begin set NEW.bouquet = '["12","10","11","8","9","6","7","5","4","3","2","1"]' MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4 – Ahmed Kaicer Feb 23 '20 at 17:55
  • I don't know phpmyadmin, but you may need to change the SQL delimiter. By default is usually a semi-colon in most tools. That doesn't work for triggers, functions, and/or stored procedures. – The Impaler Feb 23 '20 at 17:58