mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
197 lines
16 KiB
HTML
197 lines
16 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>Send an unbuffered SQL query to Ingres</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.ingres-unbuffered-query" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">ingres_unbuffered_query</h1>
|
|
<p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">ingres_unbuffered_query</span> — <span class="dc-title">Send an unbuffered SQL query to Ingres</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.ingres-unbuffered-query-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>ingres_unbuffered_query</strong></span>
|
|
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
|
|
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$params</code></span>
|
|
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$types</code></span>
|
|
]] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>ingres_unbuffered_query()</strong></span> sends the given
|
|
<code class="parameter">query</code> to the Ingres server.
|
|
</p>
|
|
<p class="para">
|
|
The query becomes part of the currently open transaction. If
|
|
there is no open transaction, <span class="function"><strong>ingres_unbuffered_query()</strong></span>
|
|
opens a new transaction. To close the transaction, you can
|
|
call either <span class="function"><a href="ingres_commit.html" class="function">ingres_commit()</a></span> to commit the changes
|
|
made to the database or <span class="function"><a href="ingres_rollback.html" class="function">ingres_rollback()</a></span> to
|
|
cancel these changes. When the script ends, any open transaction
|
|
is rolled back (by calling
|
|
<span class="function"><a href="ingres_rollback.html" class="function">ingres_rollback()</a></span>). You can also use
|
|
<span class="function"><a href="ingres_autocommit.html" class="function">ingres_autocommit()</a></span> before opening a new
|
|
transaction to have every SQL query immediately committed.
|
|
Ingres allows only a single unbuffered statement to be active at any
|
|
one time. The extension will close any active unbuffered statements before
|
|
executing any SQL. In addition you cannot use
|
|
<span class="function"><a href="ingres_result_seek.html" class="function">ingres_result_seek()</a></span> to position the row before
|
|
fetching.
|
|
</p>
|
|
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<strong>Related Configurations</strong><br />
|
|
<p class="para">
|
|
See also the <a href="ingres.configuration.html#ini.ingres.describe" class="link">ingres.describe</a>
|
|
and <a href="ingres.configuration.html#ini.ingres.utf8" class="link">ingres.utf8</a> directives in
|
|
<a href="ingres.configuration.html" class="link">Runtime Configuration</a>.
|
|
</p>
|
|
</p></blockquote>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.ingres-unbuffered-query-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">link</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The connection link identifier
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">query</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A valid SQL query (see the Ingres <em class="emphasis">SQL reference
|
|
guide</em>) in the Ingres documentation.
|
|
See the <a href="ingres-query.html#function.ingres-query.query" class="link">query</a>
|
|
parameter in <span class="function"><a href="ingres_query.html" class="function">ingres_query()</a></span> for a list of SQL
|
|
statements that cannot be executed via
|
|
<span class="function"><strong>ingres_unbuffered_query()</strong></span>.
|
|
</p>
|
|
<p class="para">
|
|
Data inside the query should be <a href="ingres_escape_string.html" class="link">properly escaped</a>.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">params</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
An array of parameter values to be used with the query
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">types</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
A string containing a sequence of types for the parameter values
|
|
passed. See the <a href="ingres-query.html#function.ingres-query.types" class="link">types</a> parameter in
|
|
<span class="function"><a href="ingres_query.html" class="function">ingres_query()</a></span> for the list of type codes.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.ingres-unbuffered-query-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
<span class="function"><strong>ingres_unbuffered_query()</strong></span> returns a query result identifier when
|
|
there are rows to fetch; else it returns <strong><code>FALSE</code></strong> when there are no rows, as
|
|
is the case of an INSERT, UPDATE, or DELETE statement. To see if an error
|
|
occurred, use <span class="function"><a href="ingres_errno.html" class="function">ingres_errno()</a></span>,
|
|
<span class="function"><a href="ingres_error.html" class="function">ingres_error()</a></span>, or
|
|
<span class="function"><a href="ingres_errsqlstate.html" class="function">ingres_errsqlstate()</a></span>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.ingres-unbuffered-query-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-1316">
|
|
<p><strong>Example #1 Issue a simple un-buffered select</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">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">ingres_unbuffered_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #DD0000">"select * from user_profile"</span><span style="color: #007700">);<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">ingres_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br /> echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="example" id="example-1317">
|
|
<p><strong>Example #2 Passing query parameters to <span class="function"><strong>ingres_unbuffered_query()</strong></span></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">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[] = </span><span style="color: #DD0000">"Emma"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"select * from user_profile where up_first = ?"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">ingres_unbuffered_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #0000BB">$query</span><span style="color: #007700">, </span><span style="color: #0000BB">$params</span><span style="color: #007700">);<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">ingres_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">];<br /> echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="example" id="example-1318">
|
|
<p><strong>Example #3 Inserting a BLOB with parameter types</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">ingres_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//Open a photo<br /></span><span style="color: #0000BB">$fh </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"photo.jpg"</span><span style="color: #007700">,</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$blob_data </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_get_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">$fh</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//Prepare parameters<br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[] = </span><span style="color: #0000BB">$blob_data</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$params</span><span style="color: #007700">[] = </span><span style="color: #0000BB">1201</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//Define parameter types<br /></span><span style="color: #0000BB">$param_types </span><span style="color: #007700">= </span><span style="color: #DD0000">"Bi"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"update user_profile set up_image = ? where up_id = ?"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">ingres_unbuffered_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #0000BB">$query </span><span style="color: #007700">, </span><span style="color: #0000BB">$params</span><span style="color: #007700">, </span><span style="color: #0000BB">$param_types</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">ingres_errno</span><span style="color: #007700">())<br />{<br /> echo </span><span style="color: #0000BB">ingres_errno</span><span style="color: #007700">() . </span><span style="color: #DD0000">"-" </span><span style="color: #007700">. </span><span style="color: #0000BB">ingres_error</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.ingres-unbuffered-query-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="ingres_query.html" class="function" rel="rdfs-seeAlso">ingres_query()</a> - Send an SQL query to Ingres</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_fetch_array.html" class="function" rel="rdfs-seeAlso">ingres_fetch_array()</a> - Fetch a row of result into an array</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_fetch_assoc.html" class="function" rel="rdfs-seeAlso">ingres_fetch_assoc()</a> - Fetch a row of result into an associative array</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_fetch_object.html" class="function" rel="rdfs-seeAlso">ingres_fetch_object()</a> - Fetch a row of result into an object</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_fetch_row.html" class="function" rel="rdfs-seeAlso">ingres_fetch_row()</a> - Fetch a row of result into an enumerated array</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_commit.html" class="function" rel="rdfs-seeAlso">ingres_commit()</a> - Commit a transaction</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_rollback.html" class="function" rel="rdfs-seeAlso">ingres_rollback()</a> - Roll back a transaction</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_autocommit.html" class="function" rel="rdfs-seeAlso">ingres_autocommit()</a> - Switch autocommit on or off</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_set_environment.html" class="function" rel="rdfs-seeAlso">ingres_set_environment()</a> - Set environment features controlling output options</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_errno.html" class="function" rel="rdfs-seeAlso">ingres_errno()</a> - Get the last Ingres error number generated</span></li>
|
|
<li class="member"><span class="function"><a href="ingres_error.html" class="function" rel="rdfs-seeAlso">ingres_error()</a> - Get a meaningful error message for the last error generated</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |