📄 function.db2-conn-error.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns a string containing the SQLSTATE returned by the last connection attempt</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.db2-commit.html">db2_commit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-conn-errormsg.html">db2_conn_errormsg</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.db2-conn-error" class="refentry"> <div class="refnamediv"> <h1 class="refname">db2_conn_error</h1> <p class="verinfo">(PECL ibm_db2:1.0-1.6.2)</p><p class="refpurpose"><span class="refname">db2_conn_error</span> — <span class="dc-title"> Returns a string containing the SQLSTATE returned by the last connection attempt </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>db2_conn_error</b></b></span> ([ <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$connection</tt></span> ] )</div> <p class="para rdfs-comment"> <b>db2_conn_error()</b> returns an SQLSTATE value representing the reason the last attempt to connect to a database failed. As <a href="function.db2-connect.html" class="function">db2_connect()</a> returns <b><tt>FALSE</tt></b> in the event of a failed connection attempt, you do not pass any parameters to <b>db2_conn_error()</b> to retrieve the SQLSTATE value. </p> <p class="para"> If, however, the connection was successful but becomes invalid over time, you can pass the <i><tt class="parameter">connection</tt></i> parameter to retrieve the SQLSTATE value for a specific connection. </p> <p class="para"> To learn what the SQLSTATE value means, you can issue the following command at a DB2 Command Line Processor prompt: <strong class="userinput"><code>db2 '? <i><tt class="parameter">sqlstate-value</tt></i>'</code></strong>. You can also call <a href="function.db2-conn-errormsg.html" class="function">db2_conn_errormsg()</a> to retrieve an explicit error message and the associated SQLCODE value. </p> </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"> A connection resource associated with a connection that initially succeeded, but which over time became invalid. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the SQLSTATE value resulting from a failed connection attempt. Returns an empty string if there is no error associated with the last connection attempt. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Retrieving an SQLSTATE value for a failed connection attempt</b></p> <div class="example-contents"><p> The following example demonstrates how to return an SQLSTATE value after deliberately passing invalid parameters to <a href="function.db2-connect.html" class="function">db2_connect()</a>. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'badname'</span><span style="color: #007700">, </span><span style="color: #DD0000">'baduser'</span><span style="color: #007700">, </span><span style="color: #DD0000">'badpassword'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br /> print </span><span style="color: #DD0000">"SQLSTATE value: " </span><span style="color: #007700">. </span><span style="color: #0000BB">db2_conn_error</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>SQLSTATE value: 08001</pre></div> </pre></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.db2-conn-errormsg.html" class="function" rel="rdfs-seeAlso">db2_conn_errormsg()</a></li> <li class="member"><a href="function.db2-connect.html" class="function" rel="rdfs-seeAlso">db2_connect()</a></li> <li class="member"><a href="function.db2-stmt-error.html" class="function" rel="rdfs-seeAlso">db2_stmt_error()</a></li> <li class="member"><a href="function.db2-stmt-errormsg.html" class="function" rel="rdfs-seeAlso">db2_stmt_errormsg()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-commit.html">db2_commit</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-conn-errormsg.html">db2_conn_errormsg</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -