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.     protected function configure({
  41.         if (!extension_loaded("mysql")) {
  42.             trigger_error(PoAUtils::msg('extension-required'array("mysql"))E_USER_ERROR);
  43.         }
  44.         parent::configure();
  45.     }
  46.  
  47.     function open({
  48.         $this->prefix = $this->cfg->getDBPrefix();
  49.         $this->db = @mysql_connect($this->cfg->getDBHost()$this->cfg->getDBUser()$this->cfg->getDBPassword());
  50.         if (!$this->dbreturn false;
  51.         if (!@mysql_select_db($this->cfg->getDBName()$this->db)) return false;
  52.         $this->create_sql = str_replace("##PREFIX##"$this->prefix$this->create_sql);
  53.         if (!@mysql_query($this->create_sql$this->db)) return false;
  54.         return true;
  55.     }
  56.  
  57.     function getError({
  58.         return @mysql_error($this->db);
  59.     }
  60.  
  61.     function check($key{
  62.         $this->search_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->search_sql);
  63.         $res @mysql_query($this->search_sql$this->db);
  64.         return (@mysql_fetch_assoc($res)) true false;
  65.     }
  66.  
  67.     function replace($key$value{
  68.         if ($this->check($key$this->db)) {
  69.             $this->update_sql = str_replace(array("##KEY##""##VALUE##""##PREFIX##")array($key$value$this->prefix)$this->update_sql);
  70.             return (@mysql_query($this->update_sql$this->db)) true false;
  71.         else {
  72.             $this->insert_sql = str_replace(array("##KEY##""##VALUE##""##PREFIX##")array($key$value$this->prefix)$this->insert_sql);
  73.             return (@mysql_query($this->insert_sql$this->db)) true false;
  74.         }
  75.     }
  76.  
  77.     function fetch($key{
  78.         $this->search_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->search_sql);
  79.         $res @mysql_query($this->search_sql$this->db);
  80.         return @mysql_fetch_assoc($res);
  81.     }
  82.  
  83.     function fetch_all({
  84.         $this->search_all_sql = str_replace("##PREFIX##"$this->prefix$this->search_all_sql);
  85.         $res @mysql_query($this->search_all_sql$this->db);
  86.         return @mysql_fetch_assoc($res);
  87.     }
  88.  
  89.     function delete($key{
  90.         $this->delete_sql = str_replace(array("##KEY##""##PREFIX##")array($key$this->prefix)$this->delete_sql);
  91.         return (@mysql_query($this->delete_sql$this->db)) true false;
  92.     }
  93.  
  94.     function close({
  95.         @mysql_close($this->db);
  96.     }
  97.  
  98. }
  99.  
  100. ?>

Documentation generated on Mon, 20 Feb 2012 12:07:02 +0100 by phpDocumentor 1.4.3