Initial commit

This commit is contained in:
Némunaire 2013-10-09 15:40:23 +02:00
commit 998d011cd3
233 changed files with 36893 additions and 0 deletions

28
onyx/modules/db/main.php Normal file
View file

@ -0,0 +1,28 @@
<?php
if(!defined('ONYX')) exit;
switch($OPT['type'])
{
case 'mysql':
case 'postgresql':
$api = array('mysql' => 'mysql_connect', 'postgresql' => 'pg_connect');
if(!function_exists($api[$OPT['type']])) trigger_error('API introuvable',E_USER_ERROR);
unset($api);
function dbpass($crypt,$cle)
{
return cxor(base64_decode($crypt),md5($cle,TRUE));
}
$db_config = $OPT;
require_once($OPT['type'].'.class.php');
define('DB_TYPE',$OPT['type']);
break;
default: trigger_error('Base de donnee inconnue',E_USER_ERROR);
}
?>

View file

@ -0,0 +1,171 @@
<?php
class BDD
{
var $connected;
private $session;
private $reponse;
var $host;
var $user;
private $password;
var $database;
var $num_rows;
var $nodb;
function __construct($profile=NULL)
{
if($profile === FALSE) return FALSE;
global $db_config;
if(empty($profile))
{
if(!$db_config['profile']) return FALSE;
$profile = &$db_config['profile'];
}
if(!ctype_alnum($profile)) trigger_error('Le nom du profil contient des caracteres illegaux',E_USER_ERROR);
if($db_config['profile'])
{
require(ONYX.'db/'.$profile.'.profile.php');
$db = &$___profile['db'];
$host = &$___profile['host'];
$user = &$___profile['user'];
$pass = &$___profile['pass'];
}
if($db_config['crypt']) $pass = dbpass($pass,$db_config['crypt']);
return $this->connexion($host,$user,$pass,$db);
}
function connexion($host,$user,$pass,$db=NULL)
{
if($this->session) $this->deconnexion();
$this->reponse = NULL;
$this->session = mysql_connect($host,$user,$pass);
if(!$this->session)
{
elog('Connexion impossible a la base de donnee : '.$this->erreur(),2);
if(function_exists($this->nodb)) call_user_func($this->nodb);
return FALSE;
}
mysql_query('SET CHARACTER SET "utf8"',$this->session);
$this->host = $host;
$this->user = $user;
$this->password = $pass;
if($db) $this->db($db);
$this->connected = TRUE;
return TRUE;
}
function reconnexion()
{
if(!empty($this->host) && !empty($this->user) && !empty($this->password) && !empty($this->database)) return $this->connexion($this->host,$this->user,$this->password,$this->database);
}
function deconnexion()
{
if(!$this->session) return FALSE;
$r = mysql_close($this->session);
$this->session = FALSE;
$this->connected = FALSE;
return $r;
}
function erreur()
{
if(!$this->session) return FALSE;
return mysql_error($this->session);
}
function db($db=NULL)
{
if(!$this->session) return FALSE;
return $this->database = mysql_select_db($db,$this->session) ? $db : $this->database;
}
function escape(&$var)
{
if(!$this->session) return FALSE;
$var = mysql_real_escape_string($var,$this->session);
return $var;
}
function query($query)
{
if(!$this->session) return FALSE;
$this->reponse = mysql_query($query,$this->session);
global $db_config;
if(!$this->reponse && $db_config['log']) elog('Erreur Mysql: " '.$this->erreur().' ", avec la requète: { '.$query.' }.',1);
$this->num_rows = @mysql_num_rows($this->reponse);
if($this->num_rows == 0) return NULL;
elseif($this->num_rows >= 1)
{
for($i=0; $var = mysql_fetch_assoc($this->reponse); $i++) $sortie[$i] = $var;
return $sortie;
}
else return FALSE;
}
function unique_query($query)
{
if(!$this->session) return FALSE;
$this->reponse = mysql_query($query,$this->session);
global $db_config;
if(!$this->reponse && $db_config['log']) elog('Erreur Mysql: " '.$this->erreur().' ", avec la requète: { '.$query.' }.',1);
$this->num_rows = @mysql_num_rows($this->reponse);
if($this->num_rows == 0) return NULL;
elseif($this->num_rows >= 1) return mysql_fetch_assoc($this->reponse);
else return FALSE;
}
function affected()
{
if(!$this->session) return FALSE;
return mysql_affected_rows($this->session);
}
function insert_id()
{
if(!$this->session) return FALSE;
return mysql_insert_id($this->session);
}
}
?>

View file

@ -0,0 +1,169 @@
<?php
class BDD
{
var $connected;
private $session;
private $reponse;
var $host;
var $user;
private $password;
var $database;
var $num_rows;
var $nodb;
function __construct($profile=NULL)
{
if($profile === FALSE) return FALSE;
global $db_config;
if(empty($profile))
{
if(!$db_config['profile']) return FALSE;
$profile = &$db_config['profile'];
}
if(!ctype_alnum($profile)) trigger_error('Le nom du profil contient des caracteres illegaux',E_USER_ERROR);
if($db_config['profile'])
{
require(ONYX.'db/'.$profile.'.profile.php');
$db = &$___profile['db'];
$host = &$___profile['host'];
$user = &$___profile['user'];
$pass = &$___profile['pass'];
}
if($db_config['crypt']) $pass = dbpass($pass,$db_config['crypt']);
return $this->connexion($host,$user,$pass,$db);
}
function connexion($host,$user,$pass,$db=NULL)
{
if($this->session) $this->deconnexion();
$this->reponse = NULL;
$host = pg_escape_string($host);
$user = pg_escape_string($user);
$pass = pg_escape_string($pass);
$db = pg_escape_string($db);
$this->session = pg_connect("host='$host' port=5432 dbname='$db' user='$user' password='$pass'");
if(!$this->session)
{
elog('Connexion impossible a la base de donnee : '.$this->erreur(),2);
if(function_exists($this->nodb)) call_user_func($this->nodb);
return FALSE;
}
pg_setclientencoding($this->session,'UTF8');
$this->host = $host;
$this->user = $user;
$this->password = $pass;
$this->database = $db;
$this->connected = TRUE;
return TRUE;
}
function reconnexion()
{
if(!empty($this->host) && !empty($this->user) && !empty($this->password) && !empty($this->database)) return $this->connexion($this->host,$this->user,$this->password,$this->database);
}
function deconnexion()
{
if(!$this->session) return FALSE;
$r = pg_close($this->session);
$this->session = FALSE;
$this->connected = FALSE;
return $r;
}
function erreur()
{
if(!$this->session) return FALSE;
return pg_last_error($this->session);
}
function db($db)
{
if(!$this->session) return FALSE;
return $this->database = pg_query($this->session,"\\connect ".pg_escape_string($db)) ? $db : $this->database;
}
function escape(&$var)
{
if(!$this->session) return FALSE;
$var = pg_escape_string($this->session,$var);
return $var;
}
function query($query)
{
if(!$this->session) return FALSE;
$this->reponse = pg_query($this->session,$query);
global $db_config;
if(!$this->reponse && $db_config['log']) elog('Erreur PostgreSQL: " '.$this->erreur().' ", avec la requète: { '.$query.' }.',1);
$this->num_rows = pg_num_rows($this->reponse);
if($this->num_rows == 0) return NULL;
elseif($this->num_rows >= 1)
{
for($i=0; $var = pg_fetch_assoc($this->reponse); $i++) $sortie[$i] = $var;
return $sortie;
}
else return FALSE;
}
function unique_query($query)
{
if(!$this->session) return FALSE;
$this->reponse = pg_query($this->session,$query);
global $db_config;
if(!$this->reponse && $db_config['log']) elog('Erreur PostgreSQL: " '.$this->erreur().' ", avec la requète: { '.$query.' }.',1);
$this->num_rows = pg_num_rows($this->reponse);
if($this->num_rows == 0) return NULL;
elseif($this->num_rows >= 1) return pg_fetch_assoc($this->reponse);
else return FALSE;
}
function affected()
{
if(!$this->session) return FALSE;
return pg_affected_rows($this->reponse);
}
}
?>