php-doc-en/reference/mysql/functions/mysql-ping.xml
Philip Olson 6a0fe1549d Added an example.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163703 c90b9560-bf6c-de11-be94-00142212c4b1
2004-07-20 01:48:47 +00:00

85 lines
2.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.100 -->
<refentry id="function.mysql-ping">
<refnamediv>
<refname>mysql_ping</refname>
<refpurpose>Ping a server connection or reconnect if there is no connection</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>mysql_ping</methodname>
<methodparam choice="opt"><type>resource</type><parameter>
link_identifier
</parameter></methodparam>
</methodsynopsis>
<para>
<function>mysql_ping</function> checks whether or not the connection to
the server is working. If it has gone down, an automatic reconnection is
attempted. This function can be used by scripts that remain idle for a
long while, to check whether or not the server has closed the connection
and reconnect if necessary.
<function>mysql_ping</function> returns &true; if the connection to the
server is working, otherwise &false;.
</para>
<para>
<example>
<title>A <function>mysql_ping</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
set_time_limit(0);
$conn = mysql_connect('localhost', 'mysqluser', 'mypass');
$db = mysql_select_db('mydb');
/* Assuming this query will take a long time */
$result = mysql_query($sql);
if (!$result) {
echo 'Query #1 failed, exiting.';
exit;
}
/* Make sure the connection is still alive, if not, try to reconnect */
if (!mysql_ping($conn)) {
echo 'Lost connection, exiting after query #1';
exit;
}
mysql_free_result($result);
/* So the connection is still alive, let's run another query */
$result2 = mysql_query($sql2);
?>
]]>
</programlisting>
</example>
</para>
<para>
See also
<function>mysql_thread_id</function> and
<function>mysql_list_processes</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->