LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   DBD::mysql::st execute failed: Column count doesn't match value count at row 1 (http://www.linuxquestions.org/questions/programming-9/dbd-mysql-st-execute-failed-column-count-doesnt-match-value-count-at-row-1-a-791233/)

shifter 02-24-2010 06:09 AM

DBD::mysql::st execute failed: Column count doesn't match value count at row 1
 
I have the following perl/DBI script:
Quote:

#!/usr/bin/perl

use DBI;

my ($db, $user, $pw) = ('dbname', '****', '***********');

my $dbh = DBI->connect("DBI:mysql:$db",$user,$pw) or die "Cannot connect to $db: $DBI::errstr\n" unless (defined $dbh);

my $sth = $dbh->prepare("INSERT INTO clients VALUES('tipo','linguaggio','progetto',1);") or die "$dbh->errstr\n";
my $rc = $sth->execute or die "$dbh->errstr\n";

$dbh->disconnect;
The error message is

[Wed Feb 24 13:03:27 2010] myscript.cgi: DBD::mysql::st execute failed: Column count doesn't match value count at row 1 at myscript.cgi.
[Wed Feb 24 13:03:27 2010] myscript.cgi: DBI::db=HASH(0x8a30c60)->errstr


I am desperated. What is the problem?

Guttorm 02-24-2010 08:46 AM

Hi

It means the SQL you are trying to execute is not correct.

INSERT INTO clients VALUES('tipo','linguaggio','progetto',1)

The table called clients does not have 4 columns. If you want to insert and use default values for the other columns, you need to name each of the columns in the SQL:

INSERT INTO clients (columnName1,columnName2,columnName3,columnName4) VALUES ('tipo','linguaggio','progetto',1)

chrism01 02-24-2010 07:42 PM

Never(!) rely on inserting without specifying the col names.


All times are GMT -5. The time now is 11:27 PM.