Added an example.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@163703 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2004-07-20 01:48:47 +00:00
parent 1279a4ae7c
commit 6a0fe1549d

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.100 -->
<refentry id="function.mysql-ping">
<refnamediv>
@ -23,6 +23,38 @@
<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