Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

MySQL Database DBD Error

by dnamonk (Initiate)
on Oct 11, 2012 at 15:01 UTC ( #998469=perlquestion: print w/ replies, xml ) Need Help??
dnamonk has asked for the wisdom of the Perl Monks concerning the following question:

Hello eveybody I am getting an error while running my script which connects to the MySQL database. Below is the error. Can anybody tell me why its happening ?

DBD::mysql::st execute failed: Unknown column 'HeadName' in 'where cla +use' at ./ line 279, <FH> line 9.
Line 279 is : $sth->execute();

Also... I am using ENGINE=MyISAM DEFAULT CHARSET=utf8; while creating the table

Any clue ?


Comment on MySQL Database DBD Error
Download Code
Replies are listed 'Best First'.
Re: MySQL Database DBD Error
by Old_Gray_Bear (Bishop) on Oct 11, 2012 at 15:07 UTC
    Based on the error message, I'd hazard a guess that "HeadName" isn't the name of a column in your DB. Perhaps a re-reading of the DB schema is in order.

    I Go Back to Sleep, Now.


Re: MySQL Database DBD Error
by roboticus (Chancellor) on Oct 11, 2012 at 17:50 UTC


    If you're not using placeholders for your database code, then perhaps you've got a field with an embedded apostrophe in it. For example:

    my $t = "Bobby Tables' and HeadName=1; drop table mytable;"; my $SQL = "select * from mytable where id='$t'"; print $SQL, "\n";

    If you expand the resulting SQL and reformat it, you'll see that it's rather fortunate that HeadName isn't a column in your table!

    select * from mytable where id='Bobby Tables' and HeadName=1; drop table mytable;


    When your only tool is a hammer, all problems look like your thumb.

Re: MySQL Database DBD Error
by kennethk (Abbot) on Oct 11, 2012 at 15:03 UTC
    My guess is that there is a typo in the SQL used to create $sth. Specifically, are you sure you have a column named HeadName? If you can show us more code, we can be more helpful.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: MySQL Database DBD Error
by blue_cowdawg (Monsignor) on Oct 11, 2012 at 15:16 UTC
        Can anybody tell me why its happening ?

    As already pointed out by others, it would appear you've typoed the name of the column in your SQL or the column doesn't exist at all.

    Going further with that the first thing you should consider doing at this point is logging in using the mysql client and attempting to run the SQL code you are scripting from there. Run an "explain" on the table should give you some idea what the valid column names are.

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998469]
Approved by herveus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-12-01 03:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (792 votes), past polls