Google Answers Logo
View Question
 
Q: Cron job mySQL update script ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Cron job mySQL update script
Category: Computers > Programming
Asked by: mhffs-ga
List Price: $10.00
Posted: 30 Dec 2002 16:07 PST
Expires: 29 Jan 2003 16:07 PST
Question ID: 135172
I require a perl script (linux, apache, php, mySQL) to run as a cron
job on my php server.  I have the cron setup.  If you would like to
put together the code I would appreciate it.
No ADODB please.

Connection: 
database: MyDataBase_    
user: iact
password: guestpast
host: localhost

Querys that needs to be run:

update gnews 
set link = concat("http://www.myWeb.com/click/out.php?", link) 
where link not like '%www.myWeb.com/click/out.php?%';

update ArticleTest 
set link = concat("http://www.myWeb.com/click/out.php?", link) 
where link not like '%www.myWeb.com/click/out.php?%';
Answer  
Subject: Re: Cron job mySQL update script
Answered By: webadept-ga on 30 Dec 2002 16:27 PST
Rated:5 out of 5 stars
 
Hi, 

Here's your scipt


#!/usr/bin/perl 
# This line above needs to point to your perl program, check with your 
# ISP to make sure you have the right one. The #! is called She-Bang, 
# just ask where the Perl She-Bang line needs to point to and they
# will probably know what you are talking about. Also make sure 
# that this is the first line in the script, no space above it. 

use DBI;  #if you have Mysql it is likely that the DBI mod is installed. 
          # run the script from a command line first before setting it up
          # as a cron to see that it works right. 

$dbh= DBI->connect('DBI:mysql:MyDataBase_:localhost','iact','guestpast',undef)
     || die "Failed on DBI connect\n\n";

 # Notice here that the qq` is not a single quote, it is the mark on the 
 # same key as the ~ 
 my $q = qq` update gnews  
	     set link = concat("http://www.myWeb.com/click/out.php?", link)  
	     where link not like '%www.myWeb.com/click/out.php?%' 
	   `;
	   
 my $sth = $dbh->prepare($q);
    $sth->execute;



   $q = qq` update ArticleTest  
	    set link = concat("http://www.myWeb.com/click/out.php?", link)  
	    where link not like '%www.myWeb.com/click/out.php?%'
	   `;
	   
    $sth = $dbh->prepare($q);
    $sth->execute;

# make sure you do this especially with cronjobs # 
$dbh->disconnect;

__END__


Thanks, 

webadept-ga

Clarification of Answer by webadept-ga on 30 Dec 2002 16:37 PST
By the way, just a personal note here. I would setup different update
scripts for each update you want to do, I put both in here to show how
that is done, but from a management stand point, I would take out the
second sql update, make a copy of this and put once in each script
file. This way, if something goes wrong with one of the scripts a) the
other might still work, and b) you can trouble shoot it much faster.
For instance, if both stop working for some reason it is probably the
server or the database, not the scripts, if only one stops, you can be
pretty sure something happened either with that table or the script
itself.

Thanks again, 

webadept-ga
mhffs-ga rated this answer:5 out of 5 stars
Thanks for the script...and for the advice on the architechture for
dealing with multiple tables.
Exactly what I needed.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy