On 2009-06-29 02:58:18 -0700, Jannis Kafkoulas wrote:
> In the DBD::Mysql docu it says:
>
> # INSERT some data into 'foo'. We are using $dbh->quote() for
> # quoting the name.
> $dbh->do("INSERT INTO foo VALUES (1, " . $dbh->quote("Tim") . ")");
>
> # Same thing, but using placeholders
> $dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 2, "Jochen");
Note that there are *three* arguments after the sql query, not two.
> When I now use the statement:
>
> $dbh->do("insert into $objtbl values (?,?,?,?,?,?)",
> $name,$type,$ip,$mask,$comment,$mark);
>
> in my Perl script I get the error message:
>
> DBI::db=HASH(0x82a6388)->do(...): attribute parameter
> 'g-ef_epn-iers-ica-citrix-clients' is not a hash ref
> at dbd_ldtbl.pl line 51, <OBJ> line 2.
>
> where "g-ef_epn-iers-ica-citrix-clients" ist the value of the $name variable.
>
> Why the hell is here a hash ref expected?
Because it says so in perldoc DBI:
$rows = $dbh->do($statement, \%attr, @bind_values) or die ...
The second argument is a hashref containing attributes, and the
bind values come after that. So you want
$dbh->do("insert into $objtbl values (?,?,?,?,?,?)", {},
$name,$type,$ip,$mask,$comment,$mark);
or
$dbh->do("insert into $objtbl values (?,?,?,?,?,?)", undef,
$name,$type,$ip,$mask,$comment,$mark);
(but I prefer the former).
> I'm afraid I didn't quite understand how it realy works:-(.
Reading perldoc DBI helps :-).
hp
--
_ | Peter J. Holzer | Auf jedem Computer sollte der Satz Ludwigs II
|_|_) | Sysadmin WSR | eingeprägt stehen: "Ein ewig Rätsel will ich
| | | [email protected] | bleiben, mir und andern."
__/ | http://www.hjp.at/ | -- Wolfram Heinrich in desd
signature.asc
Description: Digital signature
