phpPoA2
[ class tree: phpPoA2 ] [ index: phpPoA2 ] [ all elements ]

Source for file GenericMySQLDB.php

Documentation is available at GenericMySQLDB.php

  1. <?php
  2. /**
  3.  * @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
  4.  *
  5.  *  This file is part of phpPoA2.
  6.  *  
  7.  *  phpPoA2 is free software: you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation, either version 3 of the License, or
  10.  *  (at your option) any later version.
  11.  *  
  12.  *  phpPoA2 is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  21.  * @version 2.0
  22.  * @author Jaime Perez <jaime.perez@rediris.es>
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * Generic MySQL database class.
  28.  * @abstract
  29.  * @package phpPoA2
  30.  * @subpackage GenericDatabaseHandlers
  31.  */
  32. abstract class GenericMySQLDB extends GenericDB {
  33.  
  34.     protected $mandatory_options = array("DBHost",
  35.                                          "DBUser",
  36.                                          "DBPassword",
  37.                                          "DBName");
  38.     protected $prefix;
  39.  
  40.     function open({
  41.         $this->prefix = $this->cfg->getDBPrefix();
  42.         $this->db = @mysql_connect($this->cfg->getDBHost()$this->cfg->getDBUser()$this->cfg->getDBPassword());
  43.         if (!$this->dbreturn false;
  44.         if (!@mysql_select_db($this->cfg->getDBName()$this->db)) return false;
  45.         $this->create_sql = str_replace("##PREFIX##"$this->prefix$this->create_sql);
  46.         if (!@mysql_query($this->create_sql$this->db)) return false;
  47.         return true;
  48.     }
  49.  
  50.     function getError({
  51.         return @mysql_error($this->db);
  52.     }
  53.  
  54.     function check($key{
  55.         $this->search_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->search_sql);
  56.         $res @mysql_query($this->search_sql$this->db);
  57.         return (@mysql_fetch_assoc($res)) true false;
  58.     }
  59.  
  60.     function replace($key$value{
  61.         if ($this->check($key$this->db)) {
  62.             $this->update_sql = str_replace(array("##KEY##""##VALUE##""##PREFIX##")array($key$value$this->prefix)$this->update_sql);
  63.             return (@mysql_query($this->update_sql$this->db)) true false;
  64.         else {
  65.             $this->insert_sql = str_replace(array("##KEY##""##VALUE##""##PREFIX##")array($key$value$this->prefix)$this->insert_sql);
  66.             return (@mysql_query($this->insert_sql$this->db)) true false;
  67.         }
  68.     }
  69.  
  70.     function fetch($key{
  71.         $this->search_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->search_sql);
  72.         $res @mysql_query($this->search_sql$this->db);
  73.         return @mysql_fetch_assoc($res);
  74.     }
  75.  
  76.     function fetch_all({
  77.         $this->search_all_sql = str_replace("##PREFIX##"$this->prefix$this->search_all_sql);
  78.         $res @mysql_query($this->search_all_sql$this->db);
  79.         return @mysql_fetch_assoc($res);
  80.     }
  81.  
  82.     function delete($key{
  83.         $this->delete_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->delete_sql);
  84.         return (@mysql_query($this->delete_sql$this->db)) true false;
  85.     }
  86.  
  87.     function close({
  88.         @mysql_close($this->db);
  89.     }
  90.  
  91. }
  92.  
  93. ?>

Documentation generated on Thu, 26 Aug 2010 13:38:49 +0200 by phpDocumentor 1.4.3