proxy.html
来自「perl教程」· HTML 代码 · 共 329 行 · 第 1/2 页
HTML
329 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>DBD::Proxy - A proxy driver for the DBI</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>DBD::Proxy - A proxy driver for the DBI</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#connecting_to_the_database">CONNECTING TO THE DATABASE</a></li>
<li><a href="#known_issues">KNOWN ISSUES</a></li>
<ul>
<li><a href="#complex_handle_attributes">Complex handle attributes</a></li>
</ul>
<li><a href="#author_and_copyright">AUTHOR AND COPYRIGHT</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>DBD::Proxy - A proxy driver for the DBI</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">use</span> <span class="variable">DBI</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$dbh</span> <span class="operator">=</span> <span class="variable">DBI</span><span class="operator">-></span><span class="keyword">connect</span><span class="operator">(</span><span class="string">"dbi:Proxy:hostname=$host;port=$port;dsn=$db"</span><span class="operator">,</span>
<span class="variable">$user</span><span class="operator">,</span> <span class="variable">$passwd</span><span class="operator">);</span>
</pre>
<pre>
<span class="comment"># See the DBI module documentation for full details</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>DBD::Proxy is a Perl module for connecting to a database via a remote
DBI driver.</p>
<p>This is of course not needed for DBI drivers which already
support connecting to a remote database, but there are engines which
don't offer network connectivity.</p>
<p>Another application is offering database access through a firewall, as
the driver offers query based restrictions. For example you can
restrict queries to exactly those that are used in a given CGI
application.</p>
<p>Speaking of CGI, another application is (or rather, will be) to reduce
the database connect/disconnect overhead from CGI scripts by using
proxying the connect_cached method. The proxy server will hold the
database connections open in a cache. The CGI script then trades the
database connect/disconnect overhead for the DBD::Proxy
connect/disconnect overhead which is typically much less.
<em>Note that the connect_cached method is new and still experimental.</em></p>
<p>
</p>
<hr />
<h1><a name="connecting_to_the_database">CONNECTING TO THE DATABASE</a></h1>
<p>Before connecting to a remote database, you must ensure, that a Proxy
server is running on the remote machine. There's no default port, so
you have to ask your system administrator for the port number. See
<a href="../../lib/DBI/ProxyServer.html">the DBI::ProxyServer manpage</a> for details.</p>
<p>Say, your Proxy server is running on machine "alpha", port 3334, and
you'd like to connect to an ODBC database called "mydb" as user "joe"
with password "hello". When using DBD::ODBC directly, you'd do a</p>
<pre>
<span class="variable">$dbh</span> <span class="operator">=</span> <span class="variable">DBI</span><span class="operator">-></span><span class="keyword">connect</span><span class="operator">(</span><span class="string">"DBI:ODBC:mydb"</span><span class="operator">,</span> <span class="string">"joe"</span><span class="operator">,</span> <span class="string">"hello"</span><span class="operator">);</span>
</pre>
<p>With DBD::Proxy this becomes</p>
<pre>
<span class="variable">$dsn</span> <span class="operator">=</span> <span class="string">"DBI:Proxy:hostname=alpha;port=3334;dsn=DBI:ODBC:mydb"</span><span class="operator">;</span>
<span class="variable">$dbh</span> <span class="operator">=</span> <span class="variable">DBI</span><span class="operator">-></span><span class="keyword">connect</span><span class="operator">(</span><span class="variable">$dsn</span><span class="operator">,</span> <span class="string">"joe"</span><span class="operator">,</span> <span class="string">"hello"</span><span class="operator">);</span>
</pre>
<p>You see, this is mainly the same. The DBD::Proxy module will create a
connection to the Proxy server on "alpha" which in turn will connect
to the ODBC database.</p>
<p>Refer to the <a href="../../lib/DBI.html">the DBI manpage</a> documentation on the <a href="../../lib/Pod/perlfunc.html#item_connect"><code>connect</code></a> method for a way
to automatically use DBD::Proxy without having to change your code.</p>
<p>DBD::Proxy's DSN string has the format</p>
<pre>
<span class="variable">$dsn</span> <span class="operator">=</span> <span class="string">"DBI:Proxy:key1=val1; ... ;keyN=valN;dsn=valDSN"</span><span class="operator">;</span>
</pre>
<p>In other words, it is a collection of key/value pairs. The following
keys are recognized:</p>
<dl>
<dt><strong><a name="item_hostname">hostname</a></strong>
<dt><strong><a name="item_port">port</a></strong>
<dd>
<p>Hostname and port of the Proxy server; these keys must be present,
no defaults. Example:</p>
</dd>
<dd>
<pre>
<span class="variable">hostname</span><span class="operator">=</span><span class="variable">alpha</span><span class="operator">;</span><span class="variable">port</span><span class="operator">=</span><span class="number">3334</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_dsn">dsn</a></strong>
<dd>
<p>The value of this attribute will be used as a dsn name by the Proxy
server. Thus it must have the format <code>DBI:driver:...</code>, in particular
it will contain colons. The <em>dsn</em> value may contain semicolons, hence
this key *must* be the last and it's value will be the complete
remaining part of the dsn. Example:</p>
</dd>
<dd>
<pre>
dsn=DBI:ODBC:mydb</pre>
</dd>
</li>
<dt><strong><a name="item_cipher">cipher</a></strong>
<dt><strong><a name="item_key">key</a></strong>
<dt><strong><a name="item_usercipher">usercipher</a></strong>
<dt><strong><a name="item_userkey">userkey</a></strong>
<dd>
<p>By using these fields you can enable encryption. If you set,
for example,</p>
</dd>
<dd>
<pre>
<span class="variable">cipher</span><span class="operator">=</span><span class="variable">$class</span><span class="operator">;</span><span class="variable">key</span><span class="operator">=</span><span class="variable">$key</span>
</pre>
</dd>
<dd>
<p>(note the semicolon) then DBD::Proxy will create a new cipher object
by executing</p>
</dd>
<dd>
<pre>
<span class="variable">$cipherRef</span> <span class="operator">=</span> <span class="variable">$class</span><span class="operator">-></span><span class="variable">new</span><span class="operator">(</span><span class="keyword">pack</span><span class="operator">(</span><span class="string">"H*"</span><span class="operator">,</span> <span class="variable">$key</span><span class="operator">));</span>
</pre>
</dd>
<dd>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?