[VPM] Mysql - Insert question

abez abez at abez.ca
Mon Apr 28 21:10:52 CDT 2003


Here try this

 $SQL = "INSERT INTO $tablename ( host, share, jobnum, kbused ) VALUES ( ?,?,?,?)";
 $dbh->prepare($SQL);
 $dbh->execute($hostname,$sharename,$jobnum,$kbused);

What you were doing wrong was not quoting your values for hostname etc. Using
prepare and ? syntax you should be able to do what you want

For more info:

man DBI
or
perldoc DBI

abram


On Mon, 28 Apr 2003, Scott wrote:

> Hi,
>   I'm only just starting to learn perl so please bare with me.
>
> I've written a small script that should update a table on an mysql db.
>
> so far I can connect to mysql be autheticated and create the table.
> I  have verified that all the varibles contain what there supposed to have
> but the INSERT fails with the message  "DBD::mysql::db do failed: You have
> an error in your SQL syntax near ' 22342132)'  at line 2 at net-space.pl
> line 50, <INFILE1> line 24."
>
> <snip>
> $SQL = "INSERT INTO $tablename ( host, share, jobnum, kbused ) VALUES (
> $hostname, $sharename, $jobnum, $kbused)";
>
> $InsertRecord = $dbh->do($SQL);
> </snip>
>
> Online examples show that the above should work..
>
> Any help / pointers would be appreciated.
>
> Scott
>
>

-- 
abez ------------------------------------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
------------------------------------------ abez



More information about the Victoria-pm mailing list