philip          Mon Jul 19 21:48:47 2004 EDT

  Modified files:              
    /phpdoc/en/reference/mysql/functions        mysql-ping.xml 
  Log:
  Added an example.
  
  
http://cvs.php.net/diff.php/phpdoc/en/reference/mysql/functions/mysql-ping.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/reference/mysql/functions/mysql-ping.xml
diff -u phpdoc/en/reference/mysql/functions/mysql-ping.xml:1.4 
phpdoc/en/reference/mysql/functions/mysql-ping.xml:1.5
--- phpdoc/en/reference/mysql/functions/mysql-ping.xml:1.4      Wed Jul  9 11:07:29 
2003
+++ phpdoc/en/reference/mysql/functions/mysql-ping.xml  Mon Jul 19 21:48:47 2004
@@ -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>
@@ -22,6 +22,38 @@
      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

Reply via email to