CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



coolkille
Novice

Mar 8, 2004, 3:20 AM

Post #1 of 8 (6461 views)
Post deleted by coolkille

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 5:30 AM

Post #2 of 8 (6460 views)
Re: [coolkille] Runing fil.sql [In reply to] Can't Post

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

Post #3 of 8 (6458 views)
Post deleted by coolkille [In reply to]

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 6:20 AM

Post #4 of 8 (6448 views)
Re: [coolkille] Runing fil.sql [In reply to] Can't Post

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

Post #5 of 8 (6447 views)
Post deleted by coolkille [In reply to]

 


davorg
Thaumaturge / Moderator

Mar 8, 2004, 7:01 AM

Post #6 of 8 (6439 views)
Re: [coolkille] Runing fil.sql [In reply to] Can't Post


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

Post #7 of 8 (6431 views)
Post deleted by coolkille [In reply to]

 


davorg
Thaumaturge / Moderator

Mar 9, 2004, 6:04 AM

Post #8 of 8 (6428 views)
Re: [coolkille] Runing fil.sql [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives