SPUG: BD::mysql::st execute failed:

Peter Darley pdarley at kinesis-cem.com
Tue Sep 19 11:39:56 PDT 2006

	Alternately, if the mysql DBD has a quote function like the postgresql one,
you can use it to make sure that the data can't change the sql statement.
This can make it a lot simpler to debug queries because you can just print
the query string and see the data in place instead of trying to match up the
content of the bind values.  For example I often have things like:

$Query = "INSERT INTO HTML_Pages (Page_ID, Type, Entity, Name, Title,
Content) VALUES (" . Quote($Args{PageID}) . ", " . Quote($Args{Type}) . ", "
. Quote($Args{Entity}) . ", " . Quote($Args{Name}) . ", " .
Quote($Args{Title}) . ", " . Quote($Args{Content}) . ")";

$Neo::DB::Shopper->do($Query) || die "Bad Query!\n\t$Query";

	This is kinda tough to read because it's a bit long...

Peter Darley

-----Original Message-----
From: spug-list-bounces+pdarley=kinesis-cem.com at pm.org
[mailto:spug-list-bounces+pdarley=kinesis-cem.com at pm.org]On Behalf Of
tcaine at cac.washington.edu
Sent: Tuesday, September 19, 2006 10:32 AM
To: luis medrano
Cc: spug-list at pm.org
Subject: Re: SPUG: BD::mysql::st execute failed:

One of your variables has a ' in it.  Use placeholders and bind values.
Try reading the perldoc for DBI, particularly the "Placeholders and Bind
Values" section.

On Tue, 19 Sep 2006, luis medrano wrote:

> Hey List,
> I have a problem I'm trying to run this piece of code inserting values to
> row in a mysql database where "post_content" is type longtext:
>       my $sth1=$dbh->prepare("INSERT INTO wp_posts(post_author, post_date,
> post_date_gmt, p
> ost_content,post_title, post_status, comment_status,
> post_modified, po
> st_modified_gmt,guid)
> t','$guid')")  or die; # "Couldnt prepare statement: " . dbh->errstr;
>       my $rv1 = $sth1->execute();
> But I'm trying to insert text file to post_content and showing this error
> when I ran the script:
> BD::mysql::st execute failed: You have an error in your SQL syntax; check
> the
> manual that corresponds to your MySQL server version for the right syntax
> use near 't know what a CHM file isNULL Just think of the Help program
> comes up when ' at line 2 at posting.pl line 75.
> But if replace the text file for a string on @post_content I have no error
> running the script. Any ideas or suggestions of what I'm doing wrong?
> Thanks,
> Luis
Seattle Perl Users Group Mailing List
     POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
    MEETINGS: 3rd Tuesdays
    WEB PAGE: http://seattleperl.org/

More information about the spug-list mailing list