Home: Perl Programming Help: DBI:
Post deleted by coolkille



coolkille
Novice

Mar 8, 2004, 3:20 AM


Views: 14391
Post deleted by coolkille

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 5:30 AM


Views: 14390
Re: [coolkille] Runing fil.sql

1/ Connect to the database.

2/ Open the file.

3/ Read the file contents into a variable.

4/ Use "do" to run the commands on the database.

Which stage were you having trouble with?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


coolkille
Novice

Mar 8, 2004, 5:57 AM


Views: 14388
Post deleted by coolkille

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 6:20 AM


Views: 14378
Re: [coolkille] Runing fil.sql

When I said "use do" I meant, "use the do method on the DBI object".

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


coolkille
Novice

Mar 8, 2004, 6:23 AM


Views: 14377
Post deleted by coolkille

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 7:01 AM


Views: 14369
Re: [coolkille] Runing fil.sql


Code
#!/usr/bin/perl 

use strict;
use warnings;
use DBI;

# 1/ Connect to database

my $dbh = DBI->connect(....) # fill in your connection params
or die DBI->errstr;

# 2/ Open file

my $file = 'fil.sql'; # or whatever
open SQL, $file or die $!;

# 3/ Read contents into a variable

my $sql = do { local $/; <SQL> }

#4/ Use "do" to execute SQL agains database

$dbh->do($sql);


Does that help?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


coolkille
Novice

Mar 9, 2004, 5:24 AM


Views: 14361
Post deleted by coolkille

 


davorg
Thaumaturge / Moderator

Mar 9, 2004, 6:04 AM


Views: 14358
Re: [coolkille] Runing fil.sql

I'm afraid that I don't really understand what you're asking. Can you try to explain it again please.

Also, as this is a news question, it would be better to start a new discussion for it instead of continuing an existing topic.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks