<!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>Sets the handler called when a server message is raised</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sybase-select-db.html">sybase_select_db</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sybase-unbuffered-query.html">sybase_unbuffered_query</a></div> <div class="up"><a href="ref.sybase.html">Sybase Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.sybase-set-message-handler" class="refentry"> <div class="refnamediv"> <h1 class="refname">sybase_set_message_handler</h1> <p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">sybase_set_message_handler</span> — <span class="dc-title">Sets the handler called when a server message is raised</span></p> </div> <div class="refsect1 description" id="refsect1-function.sybase-set-message-handler-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>sybase_set_message_handler</strong></span> ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$handler</code></span> [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>sybase_set_message_handler()</strong></span> sets a user function to handle messages generated by the server. You may specify the name of a global function, or use an array to specify an object reference and a method name. </p> </div> <div class="refsect1 parameters" id="refsect1-function.sybase-set-message-handler-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">handler</code></em></span> <dd> <p class="para"> The handler expects five arguments in the following order: message number, severity, state, line number and description. The first four are integers. The last is a string. If the function returns <strong><code>FALSE</code></strong>, PHP generates an ordinary error message. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">link_identifier</code></em></span> <dd> <p class="para"> If the link identifier isn't specified, the last opened link is assumed. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.sybase-set-message-handler-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 changelog" id="refsect1-function.sybase-set-message-handler-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.3.5</td> <td> The <em><code class="parameter">link_identifier</code></em> parameter was added. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.sybase-set-message-handler-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2198"> <p><strong>Example #1 <span class="function"><strong>sybase_set_message_handler()</strong></span> callback function</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #007700">function </span><span style="color: #0000BB">msg_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">)<br /> {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /> }<br /><br /> </span><span style="color: #0000BB">sybase_set_message_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'msg_handler'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-2199"> <p><strong>Example #2 <span class="function"><strong>sybase_set_message_handler()</strong></span> callback to a class</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #007700">class </span><span style="color: #0000BB">Sybase </span><span style="color: #007700">{<br /> function </span><span style="color: #0000BB">handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">)<br /> {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /> }<br /> }<br /><br /> </span><span style="color: #0000BB">$sybase</span><span style="color: #007700">= new </span><span style="color: #0000BB">Sybase</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">sybase_set_message_handler</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$sybase</span><span style="color: #007700">, </span><span style="color: #DD0000">'handler'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-2200"> <p><strong>Example #3 <span class="function"><strong>sybase_set_message_handler()</strong></span> unhandled messages</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">// Return FALSE from this function to indicate you can't handle<br /> // this. The error is printed out as a warning, the way you're used<br /> // to it if there is no handler installed.<br /> </span><span style="color: #007700">function </span><span style="color: #0000BB">msg_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">)<br /> {<br /> if (</span><span style="color: #0000BB">257 </span><span style="color: #007700">== </span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">) {<br /> return </span><span style="color: #0000BB">false</span><span style="color: #007700">;<br /> }<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnumber</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$state</span><span style="color: #007700">, </span><span style="color: #0000BB">$line</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /> }<br /><br /> </span><span style="color: #0000BB">sybase_set_message_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'msg_handler'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.sybase-set-message-handler-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function is only available when using the CT library interface to Sybase, and not with the DB library. </span></p></blockquote> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sybase-select-db.html">sybase_select_db</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sybase-unbuffered-query.html">sybase_unbuffered_query</a></div> <div class="up"><a href="ref.sybase.html">Sybase Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>