Mailing List Archive



Back to the month index Back to the list index

Coy, John (jcoy@arkansas.net)
Sat, 02 Sep 1995 18:32:09 -0500


Message-Id: <1.5.4.32.19950902233209.0067cc98@mail.arkansas.net>
Date: Sat, 02 Sep 1995 18:32:09 -0500
From: jcoy@arkansas.net (Coy, John)
Subject: Re: [mSQL] insert's query using variables in a perl5...

At 08:28 PM 9/2/96 +0100, you wrote:
>Hi, there.:)B
>
>On Sun, 1 Sep 1996, Luis Alberto Vianna Tavares wrote:
>
>> How can I make a insert's query using variables in a perl5 and MsqlPerl ?
>> Like:
>> INSERT INTO table( field1, field2 ) VALUES ( $var1, $var2 )
>
>As long as you put your query in double quotes, you should be fine. I.e.:
>
>$dbh->$query("INSERT INTO table(field1,field2 ) VALUES ($var1,$var2 )");
>
You'll also have to 'quote' your variables, something like this will do:

$var1 = $dbh->quote($var1);
$var2 = $dbh->quote($var2);
$dbh->query("INSERT INTO table (field1, field2) VALUES ($var1, $var2)");

Presuming $var1 and $var2 are char() type variables. If they are ints,
then you don't have to quote them at all.

--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!