Home: Perl Programming Help: DBI:
Update & Insert Syntax Problems



hancocj
Novice

Nov 4, 2002, 9:57 AM


Views: 12603
Update & Insert Syntax Problems

I would like to encode text data when updating and inserting to a mysql table. The reason I want to do this is I get syntax errors for example when the text string contains these characters e.g. ' , ). I guess my question is can this be done with encode? and if so what is the actual syntax? And can the text be decoded with a PHP script? Or is there a better way of getting around this.

Regards,

Jon


Paul
Enthusiast

Nov 4, 2002, 2:50 PM


Views: 12597
Re: [hancocj] Update & Insert Syntax Problems

You should be using $dbi->quote


hancocj
Novice

Nov 7, 2002, 3:38 PM


Views: 12590
Re: [RedRum] Update & Insert Syntax Problems

I'm sure you're right could you help me get this right. Here is what I have so far but I am still getting a syntax error.

$META_TEXT = $dbh->quote($META_TEXT);
$PARSED_TEXT = $dbh->quote($PARSED_TEXT);

if ( $url ne "" ) {
$dbh->do("update Parent set meta = $META_TEXT, text = $PARSED_TEXT, time = NULL WHERE url=$url") or die "Cannot do: " . $dbh->errstr();
}
else {
$dbh->do( "insert into Parent values ( id, $parent, $META_TEXT, text = $PARSED_TEXT, NULL )") or die "Cannot do: " . $dbh->errstr();
}


erichmusickwc
Novice

Mar 4, 2003, 3:14 PM


Views: 12527
Re: [hancocj] Update & Insert Syntax Problems


Code
else {  
$dbh->do( "insert into Parent values ( id, $parent, $META_TEXT, text = $PARSED_TEXT, NULL )") or die "Cannot do: " . $dbh->errstr();
}



Try replacing text = $PARSED_TEXT with just $PARSED_TEXT. When you're doing an insert, you shouldn't put the field name.


Paul
Enthusiast

Mar 5, 2003, 4:51 AM


Views: 12525
Re: [erichmusickwc] Update & Insert Syntax Problems

>>
When you're doing an insert, you shouldn't put the field name.
<<

If you want to specify column names you can with:

INSERT INTO Table (Col1, Col2) VALUES ('a','b')