File : PHP/MySQL.php

<?php
if(!defined("MySQL_inc"))
{
  
define("MySQL_inc","1.0");
  class 
MySQL
  
{
    function 
MySQL($serv ""$user ""$mdp "")
    {
      
//Lien null
      
$this->link false;
      
$this->dbselected false;
      
$this->returntype "Array";
      
//Connection
      
if($serv != "" && $user != "" && $mdp != "")
        
$this->Init($ser,$user,$mdp);
    }
    function 
Init($serv$user$mdp)
    {
      
//Connection
      
$this->link mysql_connect ($serv$user$mdp);
      return (bool)
$this->link;
    }
    function 
SelectDB($dbname)
    {
      if(!
$this->link)
        return 
false;
      
//Selection de la bdd
      
$this->dbselected mysql_select_db($dbname$this->link);
      return 
$this->dbselected;
    }
    function 
Query($string$array = array(), $returnid 0)
    {
      if(!
$this->link || !$this->dbselected)
        return 
false;
      
//Template : Query("{{table}}",$tab['table']="name");
      
foreach($array as $clef => $val)
      
$string str_replace("{{".$clef."}}"$val$string);
      
$id mysql_query($string$this->link);
      if(!
$id)
        return 
false;
      else
        
$this->currentresid $id;
      if(
$id !== true && $id !== false && $returnid == 0)
      {
        
$TabReturn = array();
        if(
$this->returntype == "Array")
          while(
$GetFromMysql mysql_fetch_array($id))
            
$TabReturn[] = $GetFromMysql;
        elseif(
$this->returntype == "Array")
          while(
$GetFromMysql mysql_fetch_field($id))
            
$TabReturn[] = $GetFromMysql;
        else
        {
          
$this->SetArray();
          return 
false;
        }
        return 
$TabReturn;
      }
      elseif(
$returnid == 1)
      {
        if(
$this->returntype == "Array")
          return 
mysql_fetch_array($id);
        elseif(
$this->returntype == "Array")
          return 
mysql_fetch_field($id);
        else
        {
          
$this->SetArray();
          return 
false;
        }
      }
      elseif(
$returnid == 2)
      {
        return 
$id;
      }
      else
        return 
true;
    }
    function 
SetArray()
    {
      
$this->returntype "Array";
    }
    function 
SetObject()
    {
      
$this->returntype "Object";
    }
    function 
GetLink()
    {
      return 
$this->link;
    }
    function 
SetLink($setlink)
    {
      
$this->link $setlink;
      return 
$this->link == $setlink;
    }
    function 
GetDbLink()
    {
      return 
$this->dbselected;
    }
    function 
SetDbLink($setdblink)
    {
      
$this->dbselected $setdblink;
      return 
$this->dbselected == $setdblink;
    }
    function 
GetReturnType()
    {
      return 
$this->returntype;
    }    
    function 
GetCurrentResID()
    {
      return 
$this->currentresid;
    }
    
    var 
$link;
    var 
$dbselected;
    var 
$returntype;
    var 
$currentresid;
  };
  global 
$MySQL;
  
$MySQL = new MySQL;
}
?>


Valid XHTML 1.1