view includes/class.dataaccess.php @ 70:e08186e4ed77

Ajout d'un installeur. Il est désormais possible d'utiliser ce script pour créer une installation vierge de Dual Blog, rendant presque facile la création de sa propre instance du blog :-) Une chose à noter cependant: il est encore /impératif/ de modifier le fichier pointant vers le fichier .htpass dans le .htaccess à la main pour le moment.
author Franck Deroche <webmaster@defr.org>
date Wed, 19 Mar 2008 12:08:15 +0100
parents 0071e5744311
children e4e50d4d3b7a
line wrap: on
line source
<?php
class DataAccess {
  var $host;
  var $user;
  var $pass;
  var $db;
  var $link;
  var $connOpen;
  var $results;
  var $queries;
  var $_nbQueries;
  var $_inError;
  
  function DataAccess($host=DB_HOST, $user=DB_USER, $pass=DB_PASSWORD, $db=DB_NAME) {
   $this->host=$host;
   $this->user=$user;
   $this->pass=$pass;
   $this->db = $db;
   $this->connOpen = 0;
   $this->_nbQueries = 0;
   $this->queries = array();
   $this->results = array();
   $this->Connect();
 }
 
  function Connect() {
   if($this->connOpen == 0) {
     $this->link = mysql_connect($this->host, $this->user, $this->pass);
     if($this->link === false)
     	$this->_inError = true;
     else
     	$this->_inError = !mysql_select_db($this->db, $this->link);
   }
   $this->connOpen++;
  }
  
  function Query($query, $id=0) {
   $this->_nbQueries++;
   $this->queries[$id]=$query;
   $this->Connect();
   $this->results[$id]=mysql_query($this->queries[$id], $this->link);
   $this->Close();
   if(@$num_rows=mysql_num_rows($this->results[$id]))
	return $num_rows;
   return 0;
  }
  
  function debugQuery($query, $id=0) {
  $rv = $this->Query($query, $id);
  if(mysql_errno() !== 0)
	echo("<span class='menu'>\n Query : {$query}<br />\n MySQL Answer : " . mysql_error() . "</span>");
  return $rv;
  }
  
  function GetRow($id=0) {
   if(@$row=mysql_fetch_array($this->results[$id])) {
    return $row;
   }
   return 0;    
  }
  
  function Close() {
   $this->connOpen--;
   if($this->connOpen == 0) {
    mysql_close($this->link);
   }
  }
  
  function getNbQueries() {
	return $this->_nbQueries;
  }
  
  function formatDate($timestamp, $decallage=2, $pattern='d/m/Y H:i:s') {
   return gmdate($pattern, $timestamp + $decallage * 3600);
  }
  
  function isInError()
  {
    return $this->_inError;
  }
}
?>