* */ /** * Class dbquery : Personnal Sql classes. Allow to change the databases server. * * @author Claire Figueras * @license GPL * @package Maarch LetterBox 2.3 * @version 1.1 */ class dbquery extends functions { /** * Debug mode activation * @access private * @var integer 1,0 */ private $debug; // debug mode /** * Debug query (debug mode) * @access private * @var string */ private $debug_query; // request for the debug mode /** * SQL link identifier * @access private * @var integer */ public $sql_link; // sql link identifier /** * To know where the script was stopped * @access private * @var integer */ private $what_sql_error; // to know where the script was stopped /** * SQL query * @access private * @var string */ public $query; // query /** * Number of queries made with this identifier * @access private * @var integer */ private $nb_query; // number of queries made with this identifier /** * Sent query result * @access private * @var string */ private $result; // sent query result /** * Database connection * */ public function connect() { // database connection $server = $_SESSION['config']['databaseserver']; $user = $_SESSION['config']['databaseuser']; $pass = $_SESSION['config']['databasepassword']; $this->base = $_SESSION['config']['databasename']; $this->debug = 0; $this->nb_query = 0; if( !isset($server) OR empty($server) OR !isset($user) OR empty($user) ) return false; $this->sql_link = mysql_connect($server,$user,$pass); if(!$this->sql_link) { $this->what_sql_error = 1; $this->error(); } else { if($_SESSION['config']['force_client_utf8'] == 'true') { if(mysql_client_encoding($this->sql_link) <> 'utf8' && function_exists('mysql_set_charset')) { if(!mysql_set_charset('utf8', $this->sql_link)) { $this->what_sql_error = 5; $this->error(); } } } $this->select_db(); } } /** * Database selection * */ public function select_db() { // database selection if(!mysql_select_db($this->base)) { $this->what_sql_error = 2; $this->error(); } } /** * Database query * * @param string $q_sql requete sql */ /*public function query($q_sql) { // query $this->debug_query = $q_sql; $this->query = mysql_query($q_sql); $this->nb_query++; if(!$this->query) { $this->what_sql_error = 3; $this->error(); } } */ public function query($q_sql, $catch_error = false) { // query $this->debug_query = $q_sql; $this->query = @mysql_query($q_sql); if($this->query == false && !$catch_error) { $this->what_sql_error = 3; $this->error(); } $this->nb_query++; return $this->query; } /** * Returns the query results in an object * */ public function fetch_object() { // return the query results in an object return mysql_fetch_object($this->query); } /** * Returns the query results in an array * */ public function fetch_array($result_type = MYSQL_BOTH) { // return the query results in an array return mysql_fetch_array($this->query,$result_type); } public function fetch_row() { // return the query results in an array return mysql_fetch_row($this->query); } public function fetch_assoc() { // return the query results in an array return mysql_fetch_assoc($this->query); } /** * Returns the query number of results * */ public function nb_result() { // return the query number of results return mysql_num_rows($this->query); } public function affected_rows() { return mysql_affected_rows(); } /** * Database disconnection * */ public function deco() { // disconnection if(!mysql_close($this->sql_link)) { $this->what_sql_error = 4; $this->error(); } } /** * Error management * */ private function error() { // errors gestion if($this->what_sql_error == 1) { echo "- "._CONNEXION_ERROR." -

"; } if($this->what_sql_error == 2) { echo "- "._SELECTION_BASE_ERROR." -

"; } if($this->what_sql_error == 3) { echo "- "._QUERY_ERROR." -

"; } if($this->what_sql_error == 4) { echo "- "._CLOSE_CONNEXION_ERROR." -

"; } if($this->what_sql_error == 5) { echo "- "._CHARSET_ERROR." -

"; } echo _ERROR_NUM.@mysql_errno($this->sql_link)." "._HAS_JUST_OCCURED." :
"; echo _MESSAGE." : ". @mysql_error($this->sql_link)."
"; echo _QUERY." : "; exit; } /** * Shows the query for debug * */ public function show() { // show the query for debug echo "Query : "; } } ?>