Select Git revision
db.php 17.83 KiB
<?php
/**
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* This class manages the access to the database. It basically is a wrapper for
* MDB2 with some adaptions.
*/
class OC_DB {
const BACKEND_PDO=0;
const BACKEND_MDB2=1;
static private $connection; //the prefered connection to use, either PDO or MDB2
static private $backend=null;
static private $MDB2=false;
static private $PDO=false;
static private $schema=false;
static private $affected=0;
static private $result=false;
static private $inTransaction=false;
static private $prefix=null;
static private $type=null;
/**
* check which backend we should use
* @return BACKEND_MDB2 or BACKEND_PDO
*/
private static function getDBBackend(){
$backend=self::BACKEND_MDB2;
if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
$type = OC_Config::getValue( "dbtype", "sqlite" );
if($type=='sqlite3') $type='sqlite';
$drivers=PDO::getAvailableDrivers();
if(array_search($type,$drivers)!==false){
$backend=self::BACKEND_PDO;
}
}
}
/**
* @brief connects to the database
* @returns true if connection can be established or nothing (die())
*
* Connects to the database as specified in config.php
*/
public static function connect($backend=null){
if(self::$connection){
return;
}
if(is_null($backend)){
$backend=self::getDBBackend();
}