Click here to get back home

DBI:mysql how to do multiple inserts/modification?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DBI:mysql how to do multiple inserts/modification? Tomasz Chmielewski 02-13-2008
Get Chitika Premium
Posted by Tomasz Chmielewski on February 13, 2008, 9:03 am
Please log in for more thread options
How can I do multiple database modifications without writing too much code?

For a single modification, I would write:

$SQL = "INSERT INTO aaaaa..";
$db->do($SQL);

How can I do it without repeating "$db->do($SQL);" each time?


Something like this throws an error, so obviously I must be missing
something.

$SQL = "INSERT INTO aaaaa... ;
        INSERT INTO bbbbb... ;
        INSERT INTO bbbbb... ;";
$db->do($SQL);



--
Tomasz Chmielewski
http://wpkg.org

Posted by Abigail on February 13, 2008, 9:57 am
Please log in for more thread options
_
Tomasz Chmielewski (tch@nospam.syneticon.net) wrote on VCCLXXIX September
-: How can I do multiple database modifications without writing too much code?
-:
-: For a single modification, I would write:
-:
-: $SQL = "INSERT INTO aaaaa..";
-: $db->do($SQL);
-:
-: How can I do it without repeating "$db->do($SQL);" each time?


The same as you do to avoid repeating writing the same line of code
which has nothing to do with databases: you'd write a loop.

-: Something like this throws an error, so obviously I must be missing
-: something.
-:
-: $SQL = "INSERT INTO aaaaa... ;
-:         INSERT INTO bbbbb... ;
-:         INSERT INTO bbbbb... ;";
-: $db->do($SQL);


for my $SQL ("INSERT INTO aaaaa...",
"INSERT INTO bbbbb...",
"INSERT INTO bbbbb...") {
$db -> do ($SQL);
}



Abigail
--
print 74.117.115.116.32.97.110.111.116.104.101.114.
32.80.101.114.108.32.72.97.99.107.101.114.10;

Posted by Paul Lalli on February 13, 2008, 10:08 am
Please log in for more thread options
wrote:
> How can I do multiple database modifications without writing too much code=
?
>
> For a single modification, I would write:
>
> $SQL =3D "INSERT INTO aaaaa..";
> $db->do($SQL);
>
> How can I do it without repeating "$db->do($SQL);" each time?
>
> Something like this throws an error, so obviously I must be missing
> something.
>
> $SQL =3D "INSERT INTO aaaaa... ;
> =A0 =A0 =A0 =A0 INSERT INTO bbbbb... ;
> =A0 =A0 =A0 =A0 INSERT INTO bbbbb... ;";
> $db->do($SQL);

uh. How about...

for my $stmt (split /;\n/, $SQL) {
$db->do($stmt);
}

Paul Lalli

Posted by Tomasz Chmielewski on February 13, 2008, 3:08 pm
Please log in for more thread options
Paul Lalli schrieb:
> wrote:
>> How can I do multiple database modifications without writing too much code?
>>
>> For a single modification, I would write:
>>
>> $SQL = "INSERT INTO aaaaa..";
>> $db->do($SQL);
>>
>> How can I do it without repeating "$db->do($SQL);" each time?
>>
>> Something like this throws an error, so obviously I must be missing
>> something.
>>
>> $SQL = "INSERT INTO aaaaa... ;
>> INSERT INTO bbbbb... ;
>> INSERT INTO bbbbb... ;";
>> $db->do($SQL);
>
> uh. How about...
>
> for my $stmt (split /;\n/, $SQL) {
> $db->do($stmt);
> }

Ah, that simple.
Thanks a lot.


--
Tomasz Chmielewski
http://wpkg.org

Posted by John Bokma on February 13, 2008, 10:51 am
Please log in for more thread options

> How can I do multiple database modifications without writing too much
> code?
>
> For a single modification, I would write:
>
> $SQL = "INSERT INTO aaaaa..";
> $db->do($SQL);
>
> How can I do it without repeating "$db->do($SQL);" each time?

prepare the statement, and in a loop do $sth->execute( values )

--
John

Arachnids near Coyolillo - part 1
http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html

Similar ThreadsPosted
Msql-Mysql-modules: unable to find my mySQL 'include' dir March 4, 2005, 2:57 am
can't install DBD::mysql - missing mysql.h? November 30, 2004, 4:39 pm
assigning multiple hash values to multiple variables May 2, 2006, 7:55 pm
DBD:mysql doesn't read mysql option file /etc/my.cnf file January 27, 2005, 11:19 pm
multiple changes on multiple lines April 2, 2005, 9:42 am
net::mysql January 16, 2006, 3:33 pm
Perl to MySQL? December 9, 2004, 3:29 pm
mysql: doable? January 25, 2005, 6:19 pm
Using MySQL with Perl February 3, 2005, 6:31 pm
mysql list all db name February 28, 2005, 11:23 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap