This repository has been archived on 2023-12-05. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ae75/www/classes/Cnx.class.php
2020-11-02 15:46:52 +01:00

118 lines
4.4 KiB
PHP
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* 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 3 of the License */
/* */
/* 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, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once(__DIR__."/../client/config_thelia.php");
class StaticConnection {
public static $db_handle = -1;
public static function getHandle() {
if (self::$db_handle == -1) {
self::$db_handle = @mysql_connect(
THELIA_BD_HOST,
THELIA_BD_LOGIN,
THELIA_BD_PASSWORD) or die('Le serveur de base de données n\'est pas accessible.');
mysql_query("SET NAMES UTF8", self::$db_handle);
if (! self::$db_handle && $_REQUEST['erreur'] != 1) {
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
die("Connexion à la base de données impossible");
}
mysql_select_db(THELIA_BD_NOM, self::$db_handle) or die('Echec de selection de la base de données.');
}
return self::$db_handle;
}
}
class Cnx {
public $table = "";
public $link="";
function __construct() {
$this->link = StaticConnection::getHandle();
}
public function query($query, $exception = false) {
$resul = mysql_query($query, $this->link);
if ($resul === false) {
// Tlog::error("Erreur SQL: ", $this->get_error()," - Requête: ", $query);
if($exception === true){
throw new Exception(mysql_error($this->link));
}
}
return $resul;
}
public function query_liste($query, $classname = false) {
$liste = array();
$resul = $this->query($query);
while ($resul && $row = $this->fetch_object($resul, $classname)) {
$liste[] = $row;
}
return $liste;
}
public function fetch_object($dbhandle, $classname = false) {
if ($classname !== false)
return mysql_fetch_object($dbhandle, $classname);
else
return mysql_fetch_object($dbhandle);
}
public function num_rows($dbhandle) {
return mysql_num_rows($dbhandle);
}
public function get_result($dbhandle, $row = 0, $field = 0) {
return mysql_result($dbhandle, $row, $field);
}
public function escape_string($value) {
if(get_magic_quotes_gpc()) $value = stripslashes($value);
return mysql_real_escape_string($value, $this->link);
}
public function insert_id() {
return mysql_insert_id($this->link);
}
public function get_error() {
return mysql_error($this->link);
}
}
?>