executing an SQL statement
Posted by:
Lois Kim
Date: April 10, 2007 04:15PM
Hi!
I have a sql statment stored in a .sql file and I'd like to execute the statment of the file from my perl script. This file is to generate a text file using SELECT ... INTO OUTFILE...with the file name, displaying the date it is generated.
It runs fine if I execute the file from the MySQL command line using SOURCE and the path, but it does not run if I include the SQL statement in my perl script, using '$dbh->prepare' or '$dbh->do' as follows:
(I am working on Windows and using MySQL & DBI stored in a library.)
sub payfile
{
my $dbh;
my $sth;
my $stmt;
WebDB::connect ();
$sth = $dbh->prepare(CONCAT("SELECT Caseid, Updtname, Updtaddr, Updtcsz, Payto, Chkname, Chkaddr, Chkcsz
INTO OUTFILE '", DATE_FORMAT( NOW(), '%Y%m%d'), "SS.txt'", "
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\r\n'
FROM miha2005.miha05
WHERE (Outcome=1 OR Outcome=2) AND Saqlang=3 AND Paid<>1 AND Payto<3"));
$sth->execute ();
$sth->finish ();
$dbh->disconnect ();
}
*************
If anybody can help me, I'd really appreciate it!