mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
320 lines
10 KiB
HTML
320 lines
10 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Open a connection/database</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.dbx-connect" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">dbx_connect</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.0.6, PHP 5 < 5.1.0, PECL dbx >= 1.1.0)</p><p class="refpurpose"><span class="refname">dbx_connect</span> — <span class="dc-title">Open a connection/database</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.dbx-connect-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>dbx_connect</strong></span>
|
|
( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$module</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$persistent</code></span>
|
|
] ) : <span class="type">object</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Opens a connection to a database.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.dbx-connect-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">module</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The <code class="parameter">module</code> parameter can be either a string or a
|
|
constant, though the latter form is preferred. The possible values are
|
|
given below, but keep in mind that they only work if the module is
|
|
actually loaded.
|
|
</p>
|
|
<p class="para">
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_MYSQL</code></strong> or <em>"mysql"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_ODBC</code></strong> or <em>"odbc"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_PGSQL</code></strong> or <em>"pgsql"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_MSSQL</code></strong> or <em>"mssql"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_FBSQL</code></strong> or <em>"fbsql"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_SYBASECT</code></strong> or <em>"sybase_ct"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_OCI8</code></strong> or <em>"oci8"</em>
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
<strong><code>DBX_SQLITE</code></strong> or <em>"sqlite"</em>
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">host</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The SQL server host
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">database</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The database name
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">username</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The username
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">password</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The password
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">persistent</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The <code class="parameter">persistent</code> parameter can be set to
|
|
<strong><code>DBX_PERSISTENT</code></strong>, if so, a persistent connection
|
|
will be created.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
<p class="para">
|
|
The <code class="parameter">host</code>, <code class="parameter">database</code>,
|
|
<code class="parameter">username</code> and <code class="parameter">password</code>
|
|
parameters are expected, but not always used depending on the connect
|
|
functions for the abstracted module.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.dbx-connect-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns an object on success, <strong><code>FALSE</code></strong> on error. If a connection has been
|
|
made but the database could not be selected, the connection is closed and
|
|
<strong><code>FALSE</code></strong> is returned.
|
|
</p>
|
|
<p class="para">
|
|
The returned <var class="varname"><var class="varname">object</var></var> has three properties:
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
|
|
<span class="property">database</span>
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
<span class="simpara">
|
|
It is the name of the currently selected database.
|
|
</span>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
|
|
<span class="property">handle</span>
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
It is a valid handle for the connected database, and as such it can be
|
|
used in module-specific functions (if required).
|
|
<div class="informalexample">
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$link </span><span style="color: #007700">= </span><span style="color: #0000BB">dbx_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">DBX_MYSQL</span><span style="color: #007700">, </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"db"</span><span style="color: #007700">, </span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">-></span><span style="color: #0000BB">handle</span><span style="color: #007700">); </span><span style="color: #FF8000">// dbx_close($link) would be better here<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
|
|
<span class="property">module</span>
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
<span class="simpara">
|
|
It is used internally by dbx only, and is actually the module number
|
|
mentioned above.
|
|
</span>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.dbx-connect-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<p class="para">
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>5.0.0</td>
|
|
<td>
|
|
Introduced <strong><code>DBX_SQLITE</code></strong>.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>4.3.0</td>
|
|
<td>
|
|
Introduced <strong><code>DBX_OCI8</code></strong>.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>4.2.0</td>
|
|
<td>
|
|
Introduced <strong><code>DBX_SYBASECT</code></strong>.
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td>4.1.0</td>
|
|
<td>
|
|
Introduced <strong><code>DBX_FBSQL</code></strong>.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.dbx-connect-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-971">
|
|
<p><strong>Example #1 <span class="function"><strong>dbx_connect()</strong></span> example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$link </span><span style="color: #007700">= </span><span style="color: #0000BB">dbx_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">DBX_ODBC</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </span><span style="color: #DD0000">"db"</span><span style="color: #007700">, </span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">, </span><span style="color: #0000BB">DBX_PERSISTENT</span><span style="color: #007700">)<br /> or die(</span><span style="color: #DD0000">"Could not connect"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Connected successfully"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">dbx_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.dbx-connect-notes">
|
|
<h3 class="title">注释</h3>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
Always refer to the module-specific documentation as well.
|
|
</p>
|
|
</p></blockquote>
|
|
</div>
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.dbx-connect-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="dbx_close.html" class="function" rel="rdfs-seeAlso">dbx_close()</a> - Close an open connection/database</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |