Source for file connect.php
Documentation is available at connect.php
* Fichier pour gérer la connection à la base de donnée - initialise les connexions
* LODEL - Logiciel d'Edition ELectronique.
* Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
* Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
die("inc lodelconfig please"); // security
define("DATABASE", $GLOBALS['database']);
define("DBUSERNAME", $GLOBALS['dbusername']);
define("DBPASSWD", $GLOBALS['dbpasswd']);
define("DBHOST", $GLOBALS['dbhost']);
// connect to the database server
require_once "adodb/adodb.inc.php";
$GLOBALS['db']->debug = false; // mettre à true pour activer le mode debug
if ($GLOBALS['site'] && $GLOBALS['singledatabase'] != "on") {
$GLOBALS['currentdb'] = DATABASE. "_". $GLOBALS['site'];
define("SINGLESITE", $GLOBALS['singledatabase'] == "on"); // synonyme currently but may change in the future
$info_mysql = $GLOBALS['db']->ServerInfo();
$GLOBALS['version_mysql'] = $vs_mysql[0] . $vs_mysql[1];
if ($GLOBALS['version_mysql'] > 40) {
if ($GLOBALS['db_charset'] === false) {
$GLOBALS['db_charset'] = 'utf8';
$GLOBALS['db']->execute('SET NAMES ' . $GLOBALS['db_charset']);
$GLOBALS['tp'] = $GLOBALS['tableprefix'];
* Déclenche une erreur lors d'une erreur concernant la base de données
* Positionne la connexion de la base de données sur la table principale (en cas d'installation
global $db, $maindb, $savedb;
if (DATABASE == $GLOBALS['currentdb']) {
return false; // nothing to do
return true; // try to selectdb
if (!$maindb) { // not connected
die("ERROR: reconnection is not allow with the driver: ". DBDRIVER);
* Positionne la connexion de la base de données sur la base de données du site (si Lodel est
* installé en multisite, l'unique base sinon
if (DATABASE == $GLOBALS['currentdb']) {
if ($db->selectDB($GLOBALS['currentdb'])) {
return; // try to selectdb
* Transforme les requêtes en résolvant les jointures et en cherchant les bonnes
* tables dans les bases de données (suivant notamment le préfix utilisé pour le nommage des
* @param string $query la requête à traduire
* @return string la requête traduite
// the easiest, fats replace
$query = str_replace('#_TP_', $GLOBALS['tableprefix'], $query);
if (strpos($query, '#_') !== false) {
$cmd = array ('#_MTP_' => DATABASE. '.'. $GLOBALS['tableprefix'],
'#_entitiestypesjoin_' => "$GLOBALS[tableprefix]types INNER JOIN $GLOBALS[tableprefix]entities ON $GLOBALS[tableprefix]types.id=$GLOBALS[tableprefix]entities.idtype",
'#_tablefieldsandgroupsjoin_' => "$GLOBALS[tableprefix]tablefieldgroups INNER JOIN $GLOBALS[tableprefix]tablefields ON $GLOBALS[tableprefix]tablefields.idgroup=$GLOBALS[tableprefix]tablefieldgroups.id",
'#_tablefieldgroupsandclassesjoin_' => "$GLOBALS[tableprefix]tablefieldgroups INNER JOIN $GLOBALS[tableprefix]classes ON $GLOBALS[tableprefix]classes.class=$GLOBALS[tableprefix]tablefieldgroups.class");
$query = strtr($query, $cmd);
* Fonction nécessaire pour la gestion des id numériques uniques (dans la table object)
* fonction for handling unique id
* @param string $table le nom de la table dans laquelle on veut insérer un objet
* @return integer Un entier correspondant à l'id inséré.
$db->execute(lq("INSERT INTO #_TP_objects (class) VALUES ('$table')")) or dberror();
* Suppression d'un identifiant uniques (table objets)
* Cette fonction accepte en entrée un id ou un tableau d'id
* @param integer or array un id ou un tableau d'ids.
$db->execute(lq("DELETE FROM $GLOBALS[tableprefix]objects WHERE id IN (". join(",", $id). ")"));
$db->execute(lq("DELETE FROM $GLOBALS[tableprefix]objects WHERE id='$id'"));
* Recherche d'une variable MySQL
* @param string $database_name nom de la base de donnée
* @param string $var nom de la variable recherchée
* @return valeur de la variable
mysql_select_db($database_name) or die ("ERROR select database");
$result = mysql_query("SHOW VARIABLES LIKE '$var'");
if ($db_charset = mysql_fetch_row($result)) {
|