in reply to Error in $sth->execute()
Hi ravi45722,
You should put DBI->trace; or $sth->trace; in your code. It will show you all the debug output from the DBI, including the actual SQL statement that your code is passing, so you can see if it's what you thought it was.
You can't assemble your update SQL and pass it in as the value of the single placeholder you've declared in your statement for ON DUPLICATE KEY UPDATE . If you want multiple columns to be affected by the UPDATE, you'll have to include them and assign them placeholders.
(I can see that you will have a problem with this technique when you want to do ON DUPLICATE KEY UPDATE but you don't want to overwrite values that exist for categories that are null in the current insert. It may that you need to step back and reexamine your task, maybe redesign your DB schema, maybe get your input data in a different format. For one example, you might want your database to have a separate table that just stores preferences, one row for each user preference, with cols for user, category, and preference.)$dbh->prepare(" insert into user_master (msisdn,cat0,cat1,cat2,cat3,cat4,cat5,cat6 +,cat7,vip,SAcode,phone_type) values ( ?, ?, ?, ?, ?, ?, ?, ? +, ?, ?, ?, ?) on duplicate key update cat0=?, cat1=?, cat2=? "); # ^^^ etc.
Also I noticed a couple of minor things:
is better written as$db_update_cmd = $db_update_cmd."cat$cat=1,";
And$db_update_cmd .= "cat$cat=1,";
looks like it should beif ( $preference =~ tr/0//)
if ( $preference =~ /0/ ) # should be a more robust regexp to only capture '0', this is just to +show the right operator
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Error in $sth->execute()
by ravi45722 (Pilgrim) on Feb 20, 2016 at 04:24 UTC | |
|
Re^2: Error in $sth->execute()
by ravi45722 (Pilgrim) on Feb 20, 2016 at 04:31 UTC | |
by 1nickt (Canon) on Feb 20, 2016 at 05:01 UTC | |
by poj (Abbot) on Feb 20, 2016 at 15:09 UTC |