<?php
/* Please see the README and LICENSE files. */
/**
* Data access object for databases
*/
abstract class Data_Storage_DatabaseController extends Data_Storage_Controller {
protected static $default_control = "Data_Storage_Mysql";
/**
* Connect to the database
*
* @param String $location Where to connect to
* @param String $user Username
* @param String $pw The password
* @param String $db The database to connect to
*/
abstract public function connect($location=NULL,$user=NULL,$pw=NULL,$db=NULL, $read_only=true,$preparedStmt=false);
/**
* Disconnect from the database
*/
abstract public function disconnect();
/**
* Run a query
*
* @param String $sql The sql with all parameters replaced with ?
* @param The parameters in the format array($types,$p[1],$p[2]...,$p[n])
*/
abstract public function query($sql,$params=NULL);
/**
* Get the results from the query
* @return String[]
*/
abstract public function get_result();
/**
* Get any errors which have occured
*/
abstract public function get_error();
/**
* Get the default concrete controller
* @return DatabaseController
*/
public static function get_default(){
return new self::$default_control();
}
/**
* @see Data_Storage_Controller
*
* @param Mixed[] $subsystem Can be string or array, spaces and array elements seperated by default seperator
* @return sring The location
*/
public function translate_location($subsystem, $model) {
return substr($this->translate($subsystem).$this->translate($model),0,-1);
}
/**
* Translate the locations
*
* @param Mixed[] $in Either a string or an array
* @return string
*/
protected function translate($in){
if(!is_array($in)){
$in = explode(" ",$in);
}
$out = "";
foreach($in as $p){
$out .= str_replace(" ","",$p)."_";
}
return $out;
}
}
?>