Hi,
I wrote a
perl script to create and upload data to a mysql data base. Please see the script as shown below,
Code:
#!/usr/bin/perl -w
#Defenetion of modules use in this scrpt
use CGI qw(:standard);
use DBI ;
my $datetable1 = `date +%Y%m%d`;
my $datetable = $datetable1 ;
print ${datetable} ;
# set the data source name
# format: dbi:db type:db name:host:port
# mysqls default port is 3306
# if you are running mysql on another host or port,
#you must change it
my $dsn = 'dbi:mysql:ppscdr:localhost:3306';
# set the user and password
my $user = 'perl';
my $pass = 'perl';
# now connect and get a database handle
my $dbh = DBI->connect($dsn, $user, $pass)
or die "Cant connect to the DB: $DBI::errstr\n";
my $sth_rec = $dbh->prepare("CREATE TABLE rec_$datetable (CallType CHAR(1) NOT NULL, CallingPartyNumber
CHAR(32) NOT NULL, CalledPartyNumber CHAR(32) NOT NULL, CallBeginTime CHAR(14) NOT NULL,
CallDuration int(8) NOT NULL, NormalFee int(8) NOT NULL,
NormaAccountBalanceAfterCall int(8) NOT NULL)");
$sth_rec->execute;
my $sth1_rec_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrrec/combined/$datetable.cdrrec.txt'
INTO TABLE rec_$datetable FIELDS TERMINATED BY '|'");
$sth1_rec_u->execute;
my $sth_smr = $dbh->prepare("CREATE TABLE smr_$datetable (CallingPartyNumber CHAR(32) NOT NULL,
CalledPartyNumber CHAR(32) NOT NULL, FeeDiductionType int(1) NOT NULL,
NormalFee int(8) NOT NULL, SmsDateTime CHAR(14) NOT NULL,
NormaAccountBalanceAfterSMS int(8) NOT NULL)");
$sth_smr->execute;
my $sth_smr_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrsmr/combined/$datetable.cdrsmr.txt'
INTO TABLE smr_$datetable FIELDS TERMINATED BY '|'");
$sth_smr_u->execute;
my $sth_p2p = $dbh->prepare("CREATE TABLE p2p_$datetable (CallingPartyNumber CHAR(32) NOT NULL,
CalledPartyNumber CHAR(32) NOT NULL,
TransferDateTime CHAR(14) NOT NULL, TransferBalance int(16) NOT NULL,
SubCosIDsnd int(8) NOT NULL, SubCosIDrsv int(8) NOT NULL,
TransferFee int(16) NOT NULL)");
$sth_p2p->execute;
my $sth_p2p_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrp2p/combined/${datetable}.cdrp2p.txt'
INTO TABLE p2p_$datetable FIELDS TERMINATED BY '|'");
$sth_p2p_u->execute;
It giving following error, please sombody tell me how can i resolve this error,
Code:
./auto_sql_upload.pl
20061201
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrrec/combined/20061201
.cdrrec.txt' (Errcode: 2) at ./auto_sql_upload.pl line 37.
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrsmr/combined/20061201
.cdrsmr.txt' (Errcode: 2) at ./auto_sql_upload.pl line 50.
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrp2p/combined/20061201
.cdrp2p.txt' (Errcode: 2) at ./auto_sql_upload.pl line 63. :mad: