Source for file class.mysql.php
Documentation is available at class.mysql.php
* @author linea21 <info@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
* MySQL data manipulation
* Initialisation de la connexion
* @param string $user : utilisateur base de données
* @param string $pass : password utilisateur base de données
* @param string $serveur : serveur de base de données
* @param string $bdd : nom de la base de données
function DBInitialise($user = '', $pass = '', $serveur = '', $bdd = '')
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.init', array('user' => $user, 'password' => $pass, 'host' => $serveur, 'db' => $bdd)));
* connexion Base de données
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.connect'));
if(defined('MOD_DEBUG') && MOD_DEBUG == true && isset ($GLOBALS['Dbg'])) {
// $Dbg->queryRel('Connecting to <i>'.SQL.'</i> DATABASE [<b>'.$this->DB_NAME.'</b>] dns: '.$this->DB_USER.':'.$this->DB_PASS.'@'.DB_HOST);
* Sélection de la Base de données
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.selectDB'));
* Gestion des erreurs MySQL
* @param string $message_err : message retourné par la requête
* @param string $query : requête provoquant l'erreur
function DBError($message_err, $query = - 1)
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.error'));
$this->_logDbError($query);
$erreur .= "SQL query : $query<br />\n";
$date = date("[D d/M/y H:i:s]<br />\n");
$erreur .= $date . PHP_EOL;
$erreur .= "running script :" . $_SERVER["SCRIPT_NAME"] . getHttpParameters(). "<br />" . PHP_EOL;;
$erreur .= "website : " . SITE_ROOT_URL . PHP_EOL;
if(defined('MOD_DEBUG') && MOD_DEBUG == true) {
* Insertion de données dans la BDD
* @param string $query : requête SQL
* @param string $returnid : Si $returnid==1 ==> renvoie last_id()
* @return integer || boolean : $result last_id()
function DBInsert ($query, $returnid = - 1)
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.insert', array('query' => $query, 'lastid' => $returnid)));
// Si returnid=1 on renvoie l'id de l'enregistrement
// A utiliser uniquement si attribut auto_increment
* effectue une requête en tous genres -UPDATE - DELETE - SELECT
* @param string $query : requête SQL
* @return boolean : $result
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.query', array('query' => $query)));
if(defined('MOD_DEBUG') && MOD_DEBUG == true && isset ($GLOBALS['Dbg'])) {
$this->_logDbQuery($query);
* @param string $query : requête SQL
* @param string $fetch : renvoie des données, valeur ASSOC (default), ARRAY, OBJECT
* @return array : $result
function DBSelect ($query, $fetch = 'ASSOC')
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.select', array('query' => $query, 'type' => $fetch)));
if ($fetch == 'OBJECT') {
if (!isset ($table)) $table = 0;
* Echappement des variables
* @param string/array $input
* @return string/array : $output
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'dbconnector.escape', array('data' => $input)), $input);
$input = $r->getReturnValue();
foreach ($input as $key => $value) {
* Retourne le nombre d'enregistrements affecté par la dernière requête
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.affected_rows'));
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'dbconnector.log_query', array('query' => $q)), $q);
$q = $r->getReturnValue();
if(defined('SQL_LOG_DEBUG') && SQL_LOG_DEBUG == 1) {
// Filter data event + return value
$r = $this->dispatcher->filter(new sfEvent($this, 'dbconnector.log_error', array('query' => $q)), $q);
$q = $r->getReturnValue();
* Retourne le nombre d'enregistrements affecté par la dernière requête
* @param string $query : requête SQL
* @return boolean : $result
// Notify the end of the current method
$this->dispatcher->notify(new sfEvent($this, 'dbconnector.close'));
|