Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Mystified by why my UPDATE statement is not reflected in my database display

by 5mi11er (Deacon)
on Jul 05, 2013 at 21:33 UTC ( [id://1042803]=note: print w/replies, xml ) Need Help??


in reply to Mystified by why my UPDATE statement is not reflected in my database display

I attempted to reduce your code to something that just set information on a static entry, then printed all the entries. From this, I was able to see that the update worked just fine. So, I'd be inclined to think that the problem might be in the complicated stuff near the end of your code, and not in the actual database update code.

-Scott

#!/usr/bin/perl -w use strict; use DBI; #use autodie; $\="\n"; my $res_tbl="SOMETABLE"; my $loc_tbl="OTHERTABLE"; my $res_select_stmt = "Select * from $res_tbl order by id"; my $loc_select_stmt = "Select location from $loc_tbl where resource_id + = ?"; my $db="SOMEDB"; my $dbun="SOMEUN"; my $dbpw = 'SOMEPW'; my $dbhost="SOMEHOST.hostedresource.com"; my $res_tbl="resource_list"; my $loc_tbl="matrix_locations"; my $drh = DBI->install_driver("mysql") || print "install_driver failed +: $DBI::errstr <br/> +"; my $dsn = "DBI:mysql:database=$db;host=$dbhost"; my $dbh = DBI->connect($dsn,$dbun,$dbpw) || print "DB connect failed: +$DBI::errstr <br/>" my $res_select_stmt = "Select * from $res_tbl order by id"; my $loc_select_stmt = "Select location from $loc_tbl where resource_id + = ?"; my $update_res_stmt = "UPDATE $res_tbl SET name=?, link=?, availabilit +y=? WHERE id=?"; print "Updating $res_tbl item with stuff \n"; my $sth = $dbh->prepare($update_res_stmt) or warn "prepare UPDATE stat +ement failed: $dbh->errstr"; my $rv = $sth->execute("test","link test", "test availability", 7) || +warn "Execute update failed: $dbh->errstr"; $sth->finish; print "$res_tbl updated with return value '$rv'.\n"; my $select_sth = $dbh->prepare($res_select_stmt) || print "prepare sta +tement failed: $DBI::errstr <br/>"; $select_sth->execute() || print "execute statement failed: $DBI::errst +r <br/>"; my $results = $select_sth->fetchall_arrayref(); $select_sth->finish(); foreach my $row (@$results){ print join ',' , @$row; print '\n'; } $dbh->disconnect();
  • Comment on Re: Mystified by why my UPDATE statement is not reflected in my database display
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1042803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found