Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4096092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:59:49+00:00 2026-05-20T19:59:49+00:00

Have some Perl code which is using the DBI module – (the code is

  • 0

Have some Perl code which is using the DBI module – (the code is at work, I can post it in the morning if needed) – but mainly trying to get a sense of what DBI needs to do an update to a row — and get either errors back, or confirmation that the UPDATE was executed.

(Below is just a basic example, feel free to give your own example and sample DDL if you want… just want some code that I know works. I’ve run my code via the Perl PtkDB debugger, and can “see” the SQL it generating and executing — even paste in in the MySQL consol and execute it… but it’s doing nothing in the Perl, even thought the select statements are working. Mainly just want a better idea of how DBI is handling UPDATE to MySQL, and if there’s any built in feature in DBI that would make debugging this more simple. Thanks!)

So, please supply one full Perl script that:

  • Sets the connection (MySQL)
  • SELECT row two based on ID and get the first and last name
  • Lowercase the names
  • UPDATE the table
  • disconnect

Sample TABLE

<COL01>Id <COL02>FirstName <COL03>LastName
<ROW01-COL01>1 <ROW01-COL02>John <ROW01-COL03>Smith
<ROW02-COL01>2 <ROW02-COL02>Jane <ROW02-COL03>Doe

UPDATE (1): Code in question is below. The ONLY thing I’ve changed is remove code not related to the issue and the config info (eg database name, user, password, etc.) and made the value production for the variables super simple. This code was created by someone else and in a legacy code base.

use strict;
use warnings;
use DBI;

sub dbOpen {
    my $dsn; 
    my $dbh;
    $dsn = "DBI:mysql:database=databasename;host=localhost;port=3306";
    $dbh = DBI->connect( $dsn, "root", "password" ) ||
    print STDERR "FATAL: Could not connect to database.\n$DBI::errstr\n";
    $dbh->{ AutoCommit } = 0;
    return($dbh);
} # END sub dbOpen

my $Data;
$Data = &dbOpen();

my ($sql,$rs,$sql_update_result);
my $column2,
my $column3;
my $id;
$column2 = 2,
$column3 = 3;
$id = 1;

$sql = "UPDATE table SET column1 = NULL, column2 = ".$column2.", column3 = ".$column3." WHERE id = ".$id.";";
$rs = $Data->prepare( $sql );
$rs->execute() || &die_clean("Couldn't execute\n$sql\n".$Data->errstr."\n" );
($sql_update_result) = $rs->fetchrow;

$Data->disconnect();

DDL for MySQL — if needed, just comment and I’ll post one.


UPDATE (2):

Final found one complete example, though it’s only for a select statement and not even inserting any VARs into the SQL: http://search.cpan.org/~timb/DBI/DBI.pm#Simple_Examples

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:59:50+00:00Added an answer on May 20, 2026 at 7:59 pm

    Almost copy and paste from DBI Synopsis:

    use DBI;
    $dbh = DBI->connect($data_source, $username, $auth, \%attr);
    $statement = "UPDATE some_table SET som_col = ? WHERE id = ?";
    $rv  = $dbh->do($statement, undef, $som_val, $id); 
    $DBI::err && die $DBI::errstr;
    $rc  = $dbh->disconnect;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Perl for some time, but today I came across this
I currently have some code which returns a sites header content back: #!/usr/bin/perl use
I have some Perl code which has file glob operation. $file1 = @ARGV[0]; @res1
I have to code some kind of (perl) script which queries a Facebook wall
I have some Perl code that executes a shell script for multiple parameters, to
I have the following perl script: $myVariable = some value; //... some code ...
I have some data generated in MATLAB that I want to process using Perl.
I have some text files which I am trying to transform with a Perl
I'm using Eclipse EPIC IDE to write some Perl CGI scripts which call some
I have some source code files which came to me by an HTML output,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.