* */ /** * 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 */ private $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 */ private $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; $this->sql_link = mysql_connect($server,$user,$pass); if(!$this->sql_link) { $this->what_sql_error = 1; $this->error(); } else { $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(); } } /** * 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() { // return the query results in an array return mysql_fetch_array($this->query); } public function fetch_row() { // return the query results in an array return mysql_fetch_row($this->query); } /** * Returns the query number of results * */ public function nb_result() { // return the query number of results return mysql_num_rows($this->query); } /** * 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." -

"; } 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 : "; } } ?>