Thread join & dbh->quote() (15 answers)
Opened by pktm at 2004-03-19 09:00

format_c
 2004-03-19 13:57
#31844 #31844
User since
2003-08-04
1706 Artikel
HausmeisterIn
[Homepage] [default_avatar]
[quote=ptk,19.03.2004, 10:32]Auch in solchen Faellen ist es besser, den Platzhalter-Mechanismus von DBI zu nutzen. Ungefaehr so (ungetesteter Code):
Code: (dl )
1
2
3
4
5
6
my $sql = "INSERT INTO db (";
$sql .= join", ", keys( %{$ref} );
$sql .= ") VALUES (";
$sql .= join", ", map { "?" } values( %{$ref} );
$sql .= ")";
my @bind = values %$ref;
[/quote]
Das tät ich dann allerdings so machen.

Code: (dl )
1
2
3
4
5
6
7
my $sql = "INSERT INTO db (";
$sql .= join", ", keys( %{$ref} );
$sql .= ") VALUES (";
$sql .= join", ", map {"?"} (1 .. scalar(values(%$ref)));
$sql .= ")";
my $sth = $dbh->prepare($sql) or die DBI::errstr;
$sth->execute(map {$dbh->quote($_)} values %$ref) or die DBI::errstr;


Gruß Alex
Edit: Code korrigiert.\n\n

<!--EDIT|format_c|1079697775-->

View full thread join & dbh->quote()