CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [newera] Using LIKE erases data: Edit Log

Veteran / Moderator

Oct 9, 2015, 8:47 AM

Views: 2740
Re: [newera] Using LIKE erases data

If $text and $fragment hold the correct values as you claim, then there's no way that the code you posted would erase the data in the "demo" column. You probably have some other code in the script that is deleting the data. Can you post the entire script?

It's clear from what you've posted that you're not using the strict pragma and probably don't even have warnings enabled. That is a really big mistake. Every script you write should load those pragmas and every var will need to be declared via the my keyword.

Your script should begin like this:


use strict;
use warnings FATAL => "all";

Using a heredoc for a short 1 line string is silly.

If you enable RaiseError in the DBI connect statement, the module will handle the error checking on the rest of the statements which means you won't need to manually check each/every statement.

Your select statement is grabbing all fields, but you're only using/needing 1 field. Don't do that. Instead, you should only select the specific field(s) that you need.

Your method of fetching/looping over the result set is way to verbose. Use a more streamlined while loop.

while (my $ref = $sth->fetchrow_hashref) {

Do not use the $dbh->do($SQL) statement inside a loop; it's very inefficient. Instead do a prepare statement, which uses placeholders, prior to the loop and do an execute statement in the loop passing $text and $fragment as the args for the statement.

(This post was edited by FishMonger on Oct 9, 2015, 8:54 AM)

Edit Log:
Post edited by FishMonger (Veteran) on Oct 9, 2015, 8:53 AM
Post edited by FishMonger (Veteran) on Oct 9, 2015, 8:53 AM
Post edited by FishMonger (Veteran) on Oct 9, 2015, 8:53 AM
Post edited by FishMonger (Veteran) on Oct 9, 2015, 8:54 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives