| 
webmaster@0
 | 
     1 <?php | 
| 
webmaster@0
 | 
     2 class DataAccess { | 
| 
webmaster@0
 | 
     3   var $host; | 
| 
webmaster@0
 | 
     4   var $user; | 
| 
webmaster@0
 | 
     5   var $pass; | 
| 
webmaster@0
 | 
     6   var $db; | 
| 
webmaster@54
 | 
     7   var $link; | 
| 
webmaster@0
 | 
     8   var $connOpen; | 
| 
webmaster@53
 | 
     9   var $results; | 
| 
webmaster@53
 | 
    10   var $queries; | 
| 
webmaster@0
 | 
    11   var $_nbQueries; | 
| 
webmaster@68
 | 
    12   var $_inError; | 
| 
webmaster@0
 | 
    13    | 
| 
webmaster@53
 | 
    14   function DataAccess($host=DB_HOST, $user=DB_USER, $pass=DB_PASSWORD, $db=DB_NAME) { | 
| 
webmaster@0
 | 
    15    $this->host=$host; | 
| 
webmaster@0
 | 
    16    $this->user=$user; | 
| 
webmaster@0
 | 
    17    $this->pass=$pass; | 
| 
webmaster@53
 | 
    18    $this->db = $db; | 
| 
webmaster@53
 | 
    19    $this->connOpen = 0; | 
| 
webmaster@0
 | 
    20    $this->_nbQueries = 0; | 
| 
franck@81
 | 
    21    $this->_inError = false; | 
| 
webmaster@53
 | 
    22    $this->queries = array(); | 
| 
webmaster@53
 | 
    23    $this->results = array(); | 
| 
webmaster@0
 | 
    24    $this->Connect(); | 
| 
webmaster@0
 | 
    25  } | 
| 
webmaster@0
 | 
    26   | 
| 
webmaster@53
 | 
    27   function Connect() { | 
| 
webmaster@53
 | 
    28    if($this->connOpen == 0) { | 
| 
franck@81
 | 
    29      $this->link = mysqli_connect($this->host, $this->user, $this->pass, $this->db); | 
| 
webmaster@68
 | 
    30      if($this->link === false) | 
| 
franck@81
 | 
    31        $this->_inError = true; | 
| 
webmaster@68
 | 
    32      else | 
| 
franck@81
 | 
    33        mysqli_set_charset($this->link, 'utf8'); | 
| 
webmaster@53
 | 
    34    } | 
| 
webmaster@53
 | 
    35    $this->connOpen++; | 
| 
webmaster@0
 | 
    36   } | 
| 
webmaster@0
 | 
    37    | 
| 
webmaster@0
 | 
    38   function Query($query, $id=0) { | 
| 
webmaster@53
 | 
    39    $this->_nbQueries++; | 
| 
webmaster@53
 | 
    40    $this->queries[$id]=$query; | 
| 
webmaster@53
 | 
    41    $this->Connect(); | 
| 
franck@81
 | 
    42    $this->results[$id]=mysqli_query($this->link, $this->queries[$id]); | 
| 
webmaster@53
 | 
    43    $this->Close(); | 
| 
franck@81
 | 
    44    if(@$num_rows=mysqli_num_rows($this->results[$id])) | 
| 
webmaster@0
 | 
    45 	return $num_rows; | 
| 
webmaster@53
 | 
    46    return 0; | 
| 
webmaster@0
 | 
    47   } | 
| 
webmaster@0
 | 
    48    | 
| 
webmaster@0
 | 
    49   function debugQuery($query, $id=0) { | 
| 
franck@83
 | 
    50     $rv = $this->Query($query, $id); | 
| 
franck@83
 | 
    51     if(mysqli_errno($this->link) !== 0) | 
| 
franck@83
 | 
    52   	echo("<span class='menu'>\n Query : {$query}<br />\n MySQL Answer : " . mysql_error() . "</span>"); | 
| 
franck@83
 | 
    53     return $rv; | 
| 
webmaster@0
 | 
    54   } | 
| 
webmaster@0
 | 
    55    | 
| 
webmaster@0
 | 
    56   function GetRow($id=0) { | 
| 
franck@81
 | 
    57    if(@$row=mysqli_fetch_array($this->results[$id])) { | 
| 
webmaster@0
 | 
    58     return $row; | 
| 
webmaster@0
 | 
    59    } | 
| 
webmaster@0
 | 
    60    return 0;     | 
| 
webmaster@0
 | 
    61   } | 
| 
webmaster@0
 | 
    62    | 
| 
webmaster@0
 | 
    63   function Close() { | 
| 
webmaster@53
 | 
    64    $this->connOpen--; | 
| 
webmaster@53
 | 
    65    if($this->connOpen == 0) { | 
| 
franck@81
 | 
    66     mysqli_close($this->link); | 
| 
webmaster@53
 | 
    67    } | 
| 
webmaster@0
 | 
    68   } | 
| 
webmaster@0
 | 
    69    | 
| 
webmaster@0
 | 
    70   function getNbQueries() { | 
| 
webmaster@0
 | 
    71 	return $this->_nbQueries; | 
| 
webmaster@0
 | 
    72   } | 
| 
webmaster@0
 | 
    73    | 
| 
webmaster@0
 | 
    74   function formatDate($timestamp, $decallage=2, $pattern='d/m/Y H:i:s') { | 
| 
webmaster@0
 | 
    75    return gmdate($pattern, $timestamp + $decallage * 3600); | 
| 
webmaster@0
 | 
    76   } | 
| 
franck@87
 | 
    77  | 
| 
franck@87
 | 
    78   function escapeString($string) { | 
| 
franck@87
 | 
    79     return mysqli_escape_string($this->link, $string); | 
| 
franck@87
 | 
    80   } | 
| 
webmaster@68
 | 
    81    | 
| 
webmaster@68
 | 
    82   function isInError() | 
| 
webmaster@68
 | 
    83   { | 
| 
webmaster@68
 | 
    84     return $this->_inError; | 
| 
webmaster@68
 | 
    85   } | 
| 
webmaster@0
 | 
    86 } | 
| 
webmaster@0
 | 
    87 ?> |