Hi everyone, I want to make sure a some values are added into a table but am having some problems.. I'm trying to use the following
$dbh = DBI->connect('dbi:mysql:dbname','user','passwd');
if($dbh->do("insert into <table-name> value('$data1','$data2 etc...)") == 1) { blah blah } else { blah blah }
But I keep on getting an error about an undefined subroutine... help please..
TIA
SImon
On Wed, 24 Jul 2002, Simon wrote:
Hi everyone, I want to make sure a some values are added into a table but am having some problems.. I'm trying to use the following
$dbh = DBI->connect('dbi:mysql:dbname','user','passwd');
if($dbh->do("insert into <table-name> value('$data1','$data2 etc...)") == 1) { blah blah } else { blah blah }
But I keep on getting an error about an undefined subroutine... help please..
TIA
SImon
Hi Simon
Do you have
Use DBI; Use DBD::mysql;
At the top of your programme? If not it wont work.
Chris
I've got: use DBI;
only
Will try the DBD::mysql
Thanks
On Wednesday 24 July 2002 12:29 pm, Chris Glover wrote:
On Wed, 24 Jul 2002, Simon wrote:
Hi everyone, I want to make sure a some values are added into a table but am having some problems.. I'm trying to use the following
$dbh = DBI->connect('dbi:mysql:dbname','user','passwd');
if($dbh->do("insert into <table-name> value('$data1','$data2 etc...)") ==
- {
blah blah } else { blah blah }
But I keep on getting an error about an undefined subroutine... help please..
TIA
SImon
Hi Simon
Do you have
Use DBI; Use DBD::mysql;
At the top of your programme? If not it wont work.
Chris
Hi,
$dbh = DBI->connect('dbi:mysql:dbname','user','passwd');
if($dbh->do("insert into <table-name> value('$data1','$data2 etc...)") ==
- {
blah blah } else { blah blah }
Is the DBI->connect line in your email exactly as you have it in the perl code? If so, then you need to replace dbname with the name of the database that you wish to work on (unless it is called dbname, in which case I am wrong). I think this may be causing the connect to fail and therefore the function $dbh->do will not work as $dbh doesn't contain a valid db handle (and all its associated functions).
Also the SQL statement needs 'value' to be replaced by 'values', but that is just me probably being a bit too pedantic on a typo that probably doesn't appear in the code.
Cheers,
Mat
Simon simon@sparksy.org.uk wrote:
if($dbh->do("insert into <table-name> value('$data1','$data2 etc...)") == 1)
General probably-unrelated-to-your-problem point: you probably want to use prepare() with ? placeholders and then execute() with the $data1, $data2, etc unless you're really sure that you don't need to escape the data in any way.
#include <anti-perl-rant>
MJR