Home: Perl Programming Help: Intermediate:
Database



andy7t
User

Oct 12, 2003, 9:04 AM


Views: 1111
Database

I realise that this should go in the DBI forum, but i didn't think it was complex enough!
I'm sure this question is really simple- just not for beginners in MySQL!

I've having diffuculty using the DBI module.
I'm using many tutorials- but i can't get beyond the SELECT function.
I got the SELECT function to work and display whats in the database, but i can't get it to add.
This code below is my attempt- it's just the $SQL variable changed to my INSERT command.
Any help appreciated.
Yhanks

use DBI;

$dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=$DBHOST;port=3306",$DBUSER,$DBPASS) or print $DBI::errstr;

$SQL = "

INSERT INTO `people`
('ID','First Name','Last Name','Age','Sex')
VALUES('3','Joe','Bloggs','40','M')

";

$cursor = $dbh->do($SQL);

$cursor->execute;

$cursor->finish;

$dbh->disconnect;


davorg
Thaumaturge / Moderator

Oct 14, 2003, 2:23 AM


Views: 1106
Re: [andy7t] Database

What errors are you seeing? Have you turned on "use strict" and "use warnings"?

The "do" method does all that you want to do. It doesn't return a cursor and there's not need to call "execute" or "finish".

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


andy7t
User

Oct 14, 2003, 8:14 AM


Views: 1104
Re: [davorg] Database

I'm now using strict and warnings- none are given.

Could you please paste some code which inserts a new row into a database.

Thanks