Source for file connect.php

Documentation is available at connect.php

  1. #!/usr/local/bin/php
  2. <?php
  3. /**
  4.  * Examples how to handle connections to MySQL.
  5.  * First connect try is without automatic error handling, second try is with automatic handling on.
  6.  * @author Sascha 'SieGeL' Pfalz <php@saschapfalz.de>
  7.  * @package db_MySQL
  8.  * @subpackage Examples
  9.  * @version 0.36 (21-Sep-2008)
  10.  *  $Id: connect.php,v 1.4 2008/11/29 12:33:00 siegel Exp $
  11.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  12.  * @filesource
  13.  */
  14. /**
  15.  */
  16. require('functions.inc.php');
  17. $db new db_MySQL('./dbdefs.inc.php');
  18.  
  19. $d WhichBR();
  20.  
  21. /*
  22.  * Turn off automatic error handling:
  23.  */
  24. $db->setErrorHandling(DBOF_RETURN_ALL_ERRORS);
  25.  
  26. echo($d['LF']."Testing connectivity to MySQL (U=".MYSQLDB_USER."|P=".MYSQLDB_PASS."|H=".MYSQLDB_HOST."|DB=".MYSQLDB_DATABASE.')'.$d['LF'].$d['LF']);
  27.  
  28. $sock $db->Connect();
  29. if(!$sock)
  30.   {
  31.   echo("Unable to connect to database(".$db->GetErrno()."): ".$db->GetErrorText().$d['LF']);
  32.   }
  33. else
  34.   {
  35.   echo('Connected'.$d['LF']);
  36.   $db->Disconnect();
  37.   }
  38.  
  39. echo($d['HR']);
  40. echo($d['LF'].'Now trying to connect with automatic error handling:'.$d['LF'].$d['LF']);
  41.  
  42. /*
  43.  * Now turn on automatic error handling:
  44.  */
  45.  
  46. $db->setErrorHandling(DBOF_SHOW_ALL_ERRORS);
  47.  
  48. $sock $db->Connect();
  49. echo('Connected'.$d['LF'].$d['LF']);
  50. $db->Disconnect();
  51. echo($d['HR']);
  52. DBFooter($d['LF'].$d['LF'],$db);
  53. ?>

Documentation generated on Sat, 07 Aug 2010 10:18:05 +0200 by phpDocumentor 1.4.3