function.pg-update.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 179 行

HTML
179
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Update table</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-untrace.html">pg_untrace</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-version.html">pg_version</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.pg-update" class="refentry"> <div class="refnamediv">  <h1 class="refname">pg_update</h1>  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_update</span> &mdash; <span class="dc-title">   Update table  </span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>pg_update</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$connection</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$table_name</tt></span>   , <span class="methodparam"><span class="type">array</span> <tt class="parameter">$data</tt></span>   , <span class="methodparam"><span class="type">array</span> <tt class="parameter">$condition</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$options</tt></span>  ] )</div>  <p class="para rdfs-comment">   <b>pg_update()</b> updates records that matches   <i>condition</i> with <i>data</i>. If   <i>options</i> is specified,   <a href="function.pg-convert.html" class="function">pg_convert()</a> is applied to   <i>data</i> with specified options.  </p>  <div class="warning"><b class="warning">Warning</b><p class="simpara">This function is<em class="emphasis">EXPERIMENTAL</em>. The behaviour of this function, its name, andsurrounding documentation may change without notice in a future release of PHP.This function should be used at your own risk.</p></div> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">connection</tt></i></span>     <dd>      <p class="para">       PostgreSQL database connection resource.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">table_name</tt></i></span>     <dd>      <p class="para">       Name of the table into which to update rows.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">data</tt></i></span>     <dd>      <p class="para">       An <a href="language.types.array.html" class="type array">array</a> whose keys are field names in the table <i><tt class="parameter">table_name</tt></i>,       and whose values are what matched rows are to be updated to.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">condition</tt></i></span>     <dd>      <p class="para">       An <a href="language.types.array.html" class="type array">array</a> whose keys are field names in the table <i><tt class="parameter">table_name</tt></i>,       and whose values are the conditions that a row must meet to be updated.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">options</tt></i></span>     <dd>      <p class="para">       Any number of <b><tt>PGSQL_CONV_OPTS</tt></b>,        <b><tt>PGSQL_DML_NO_CONV</tt></b>,       <b><tt>PGSQL_DML_EXEC</tt></b> or       <b><tt>PGSQL_DML_STRING</tt></b> combined. If <b><tt>PGSQL_DML_STRING</tt></b> is part of the       <i><tt class="parameter">options</tt></i> then query string is returned.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure.  Returns <a href="language.types.string.html" class="type string">string</a> if <b><tt>PGSQL_DML_STRING</tt></b> is passed   via <i><tt class="parameter">options</tt></i>.  </p> </div>  <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>pg_update()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php&nbsp;<br />&nbsp;&nbsp;$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'dbname=foo'</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'field1'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'AA'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'field2'</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">'BB'</span><span style="color: #007700">);<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;safe,&nbsp;since&nbsp;$_POST&nbsp;is&nbsp;converted&nbsp;automatically<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_update</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'post_log'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$res</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Data&nbsp;is&nbsp;updated:&nbsp;$res\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"User&nbsp;must&nbsp;have&nbsp;sent&nbsp;wrong&nbsp;inputs\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.pg-convert.html" class="function" rel="rdfs-seeAlso">pg_convert()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-untrace.html">pg_untrace</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-version.html">pg_version</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?