Newbie question about do()

Newbie question about do()

am 24.03.2004 00:56:20 von Charles Thomas

I'm attempting to write a PERL script to add data to a MySQL
database. I'm using DBI, which I eventually figured out how to
install (NIGHTMARE).

This code works:

$rows = $database_handle->do("INSERT dates (date, location, city, state)"
. " VALUES('2004-01-01', 'The Iron
Nail', 'Verona', 'WI')");

This code does not:

$date = "2004-01-01";
$location = "The Iron Nail";
$city = "Verona";
$state = "WI";

$rows = $database_handle->do("INSERT dates (date, location, city, state)"
. " VALUES($date, $location, $city, $state)");

It fails with "DBD::mysql::db do failed: You have an error in your
SQL syntax. Check the manual that corresponds to your MySQL server
version for the right syntax to use near 'Iron Nail, Verona, WI)' at
line 1 at ./my_script line 75, line 1."

Can anyone tell me why, or how I can use variables in my INSERT call?

Many thanks!

CT


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org