Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Re: Editing data extracted from mysql through CGI/mod_perl

by Arguile (Hermit)
on Jun 10, 2002 at 21:07 UTC ( #173300=note: print w/replies, xml ) Need Help??

in reply to Re: Editing data extracted from mysql through CGI/mod_perl
in thread Editing data extracted from mysql through CGI/mod_perl

$dbh = DBI->connect('conn_str', 'user', 'pass', { <args> });

$dbh is just a handle. It simply refers to the connection we just made to the database. As such, you can pass it anywhere and it will always represent that connection to the database. When we say my $sth = $dbh->prepare('SQL'); we're saying; use this database connection, prepare this SQL code, and return a reference to that code object. It doesn't matter what the SQL is or how many arguments you pass in $sth->execute(), as we're still using the same connection. You can $sth->finish() that statement and start another on the same $dbh because, as stated above, we're still using that same connection. No matter where you pass it or what methods you call on it (excluding disconnect of course :) it's still the same connection.

If there's a case where you use different logins or connection strings, that's when you'd need to pass a different handle. With our hypothetical generalised connection method in our application modules, we'd pass which type of connection we wanted returned. A standard approach is to make a read only user for most use and other users with varying write permissions (when you still want connection pooling).

If you don't get that last bit, don't sweat it. Keep it simple until you've got the basics of DBI down. Also you might want to check out Programming the Perl DBI. If you like your books online has all their titles at really great subscription prices.

BTW, not trying to be heavy handed or anything. My HS english teacher just said repeating in threes is a good literary device ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://173300]
[vedagiri89]: recently purchased centos server and doing migration of app
[choroba]: did you copy any dependencies?
[choroba]: all XS code needs to be recompiled
[vedagiri89]: install perl5.16 in the new server and try to run appache
[hippo]: Which version of CentOS?
[vedagiri89]: how to fix: Attempt to reload aborted
[hippo]: Ah, presumably 7 then.
[vedagiri89]: CentOS Linux release 7.0.1406 (Core)
[hippo]: How did you install libapreq2?

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-06-19 11:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (113 votes). Check out past polls.