crabs_todo-2.0 ©2008-2011 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)
1 <?php 2 // 3 // ============================================================================= 4 // crabs_todo-2.0 : Gestion simplissime des Todo 5 // Copyright (C) 2008-2011 : Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com) 6 // 7 // Ce source fait partie d'un projet logiciel libre. Vous pouvez le distribuer 8 // et/ou le modifier en respectant les termes de la GNU General Public License 9 // version 2 ou (suite a votre propre choix) une version ulterieure. 10 // 11 // Ce programme est distribue dans l'espoir qu'il puisse etre utile, mais 12 // sans aucune garantie, meme si il est associe a un produit qui vous en 13 // propose une. Conformez-vous a la GNU General Public License pour avoir 14 // plus de precisions. 15 // 16 // L'auteur ne peut etre tenu responsable de l'utilisation faite des 17 // composantes associees a ce projet (en partie ou dans leur totalite). 18 // 19 // Une copie du fichier de la GNU GPL est fournie dans le repertoire DOC 20 // de ce projet sous le nom gnu_gpl.txt 21 // 22 // ============================================================================= 23 // 24 // Cette classe fait partie du projet crabs_phplib 1.0 25 // Timestamp [[GPLLIB_TIMESTAMP=20101211-140813]] 26 class MYSQL 27 { 28 var $_c ; 29 var $_root ; 30 var $_html_err_page ; 31 32 function MYSQL( $do_connect=false, $html_err_page=true ) 33 { 34 $this->_c = false ; 35 $this->_html_err_page = $html_err_page ; 36 if ( $do_connect ) $this->connect() ; 37 } 38 function connect() 39 { 40 global $DB_HOST, $DB_USER, $DB_PASSWD, $DB_BASE ; 41 $c = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWD) 42 or $this->err("mysql_connect"); 43 mysql_select_db( $DB_BASE, $c ) or $this->err("mysql_select_db") ; 44 $this->_c = $c ; 45 } 46 function connectl( $host, $user, $pass, $db ) 47 { 48 $c = mysql_connect($host,$user,$pass) 49 or $this->err("mysql_connect"); 50 mysql_select_db( $db, $c ) or $this->err("mysql_select_db") ; 51 $this->_c = $c ; 52 } 53 function close() 54 { 55 if ( !$this->_c ) return ; 56 mysql_close($this->_c); 57 $this->_c=false; 58 } 59 function id() { return mysql_insert_id( $this->_c ) ; } 60 function query($sql) 61 { 62 if ( !$this->_c ) $this->connect() ; 63 $r = mysql_query( $sql, $this->_c ) or $this->err($sql) ; 64 return $r ; 65 } 66 function enumValue( $table, $field ) 67 { 68 $arryEnum = array() ; 69 $result=mysql_query("SHOW COLUMNS FROM $table LIKE '$field'"); 70 if( mysql_num_rows( $result ) > 0 ) 71 { 72 $row=mysql_fetch_row($result); 73 preg_match_all("/'(.*?)'/", $row['Type'], $matches); 74 $arryEnum = $matches[1] ; 75 } 76 return $arryEnum ; 77 } 78 function err( $call ) 79 { 80 global $ACCUEIL_URL ; 81 if ( $this->_c ) $err = mysql_error( $this->_c ) ; 82 else $err = mysql_error() ; 83 if ( $this->_html_err_page ) 84 echo <<<HTML 85 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" 86 "http://www.w3.org/TR/html4/strict.dtd"> 87 <html> 88 <head> 89 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"> 90 <meta http-equiv="CONTENT-LANGUAGE" content="fr"> 91 <meta name="LANGUAGE" content="fr"> 92 <title>Erreur Mysql</title> 93 </head> 94 <body> 95 <h1>URI</h1> 96 <pre>$_SERVER[REQUEST_URI]</pre> 97 <h1>CONTEXTE</h1> 98 <pre>$call</pre> 99 <h1>RAISON</h1> 100 <p>$err</p> 101 <p><br><a href="$ACCUEIL_URL">Revenir au site</a></p> 102 </body> 103 </html> 104 105 HTML; 106 else 107 echo <<<TEXT 108 ============================================================================ URI 109 $_SERVER[REQUEST_URI] 110 111 ======================================================================= CONTEXTE 112 $call 113 114 ========================================================================= RAISON 115 $err 116 117 TEXT; 118 exit() ; 119 } 120 } 121 ?>
Date de génération : 22/09/2011 21:49