Unstoppable Domains

Auto Update

Spacemail by SpaceshipSpacemail by Spaceship
Watch

NetworkTown.Net

Account Closed
Impact
2
Hi

I am making a script and i am going to add a auto-update feature that will use cron job i will tell the cron to run every hour so that it runs a file that will add the first line in update.sql and after it has ran that first line of sql i want it to delete that line so the next hour the second line will be ran and so on, dose any one has a script or code that can do this?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
There is no code in PHP, or any server side language that does this. You have to have a program running on the server itself to do this, unless you have visitors at your site full time it is not guaranteed that it will run properly.
 
0
•••
PHP:
<?php

// Put your MySQL connection stuff here

$filename = 'update.sql';

$file = file($filename);

$run = $file[0];

mysql_query($run);

$newfile = '';
foreach ($file as $linenum => $line) {
	if ($linenum != 0) {
		$newfile .= $line;
	}
}

$handle = fopen($filename, 'w');
fwrite($handle, $newfile);
fclose($handle);

?>
That will work if you have your update.sql like this:
Code:
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
 
0
•••
Dan Friedman said:
PHP:
<?php

// Put your MySQL connection stuff here

$filename = 'update.sql';

$file = file($filename);

$run = $file[0];

mysql_query($run);

$newfile = '';
foreach ($file as $linenum => $line) {
	if ($linenum != 0) {
		$newfile .= $line;
	}
}

$handle = fopen($filename, 'w');
fwrite($handle, $newfile);
fclose($handle);

?>
That will work if you have your update.sql like this:
Code:
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')
INSERT INTO whatever VALUES ('you', 'get', 'the', 'point')

Looks like dans would do the trick, just run a cron with this script and have it run every hour.
 
0
•••
Dose it delete the line after it is inserted?
 
0
•••
NetworkTown.Net said:
Dose it delete the line after it is inserted?
Yes. I removes the first line afterwards.
 
0
•••
This dose not work it delete's all the lines when you run it and it dose not put threm into the database i manually wote around 60 lines for DB and this script deleted all of them! Alot of time went down the drain! Dose any one have a proper one.
 
0
•••
Why would you manually write 60 lines?.. and why would you not save it if you knew it was going to delete some of it?

I have tested this and it only deletes the first line of the file. You can look at the code and it gets everyline except line 0 [the first line] and writes it to the file.
 
0
•••
I got it working by removing the ; at the end lol also i put it in cron job to run this file and i get a email every time a cron is run but it had errors it said:

/home/afterarc/public_html/update.php: line 1: ?php
: No such file or directory
/home/afterarc/public_html/update.php: line 2:
: command not found
/home/afterarc/public_html/update.php: line 3: =: command not found
/home/afterarc/public_html/update.php: line 3:
: command not found
/home/afterarc/public_html/update.php: line 4: syntax error near unexpected token `('
/home/afterarc/public_html/update.php: line 4: `$file = array_map('rtrim',file($filename));
'
 
0
•••
/home/afterarc/public_html/update.php: line 1: ?php
: No such file or directory
You put the wrong path to the file.

The rest of the error lines you wrote.
 
0
•••
All fixed it, also one last question is there a way i add that if the data already exist (dublicate) the above script will just delete the line and carry one to the next line is there a way to do this?
 
0
•••
Is this the exact same thing your selling?
 
0
•••
Im not selling this any more i thought i could if i changed it to a script but then dan told me i cant so im not any more, thanks every one.
 
0
•••
I didn't say you couldn't sell it, I just said you were selling something you couldn't make and that you got done for free.. I didn't know you were going to be selling it since you asked for help in this thread.

How did you change it to a script? It always was one.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back