Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

MySQL Database DBD Error

by dnamonk (Acolyte)
on Oct 11, 2012 at 15:01 UTC ( [id://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 ./program.pl 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 ?

Thanks

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.

    OGB

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

    dnamonk:

    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;

    ...roboticus

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-29 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found