CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Database

 



andy7t
User

Oct 12, 2003, 9:04 AM

Post #1 of 3 (521 views)
Database Can't Post

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

Post #2 of 3 (516 views)
Re: [andy7t] Database [In reply to] Can't Post

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

Post #3 of 3 (514 views)
Re: [davorg] Database [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives