Example #1
0
 public static function connect($type = null, $host = null, $name = null, $user = null, $pass = null)
 {
     if (!self::$dbh) {
         if ($type === null && defined('DB_TYPE')) {
             $type = DB_TYPE;
         }
         if ($host === null && defined('DB_HOST')) {
             $host = DB_HOST;
         }
         if ($name === null && defined('DB_NAME')) {
             $name = DB_NAME;
         }
         if ($user === null && defined('DB_USER')) {
             $user = DB_USER;
         }
         if ($pass === null && defined('DB_PASS')) {
             $pass = DB_PASS;
         }
         try {
             self::$dbh = new PDO($type . ':host=' . $host . ';dbname=' . $name, $user, $pass);
             self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             return self::$dbh;
         } catch (Exception $e) {
             throw new EpiDatabaseConnectionException('Could not connect to database', EpiException::EPI_EXCEPTION_DB_CONNECTION);
         }
     } else {
         return self::$dbh;
     }
 }
Example #2
0
 public function __construct($params)
 {
     parent::__construct();
     $this->db = EpiDatabase::getInstance('mysql', $params['database'], $params['host'], $params['username'], $params['password']);
     $this->table = $params['table'];
     if (isset($params['cacheMask']) && $params['cacheMask']) {
         $this->cacheMask = $params['cacheMask'];
         $this->cacheObj = getCache();
     }
 }
Example #3
0
 public static function employ($type = null, $name = null, $host = 'localhost', $user = '******', $pass = '')
 {
     if (!empty($type) && !empty($name)) {
         self::$type = $type;
         self::$name = $name;
         self::$host = $host;
         self::$user = $user;
         self::$pass = $pass;
     }
     return array('type' => self::$type, 'name' => self::$name, 'host' => self::$host, 'user' => self::$user, 'pass' => self::$pass);
 }
Example #4
0
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct($config = null, $params = null)
 {
     $this->config = !is_null($config) ? $config : getConfig()->get();
     $mysql = $this->config->mysql;
     if (!is_null($params) && isset($params['db'])) {
         $this->db = $params['db'];
     } else {
         $utilityObj = new Utility();
         EpiDatabase::employ('mysql', $mysql->mySqlDb, $mysql->mySqlHost, $mysql->mySqlUser, $utilityObj->decrypt($mysql->mySqlPassword));
         $this->db = getDatabase();
     }
     foreach ($mysql as $key => $value) {
         $this->{$key} = $value;
     }
     if (isset($this->config->user)) {
         $this->owner = $this->config->user->email;
     }
 }
Example #5
0
<?php

chdir('..');
include_once '../src/Epi.php';
Epi::setPath('base', '../src');
Epi::init('route', 'database');
EpiDatabase::employ('mysql', 'mysql', 'localhost', 'root', '');
// type = mysql, database = mysql, host = localhost, user = root, password = [empty]
// Epi::init('base','cache','session');
// Epi::init('base','cache-apc','session-apc');
// Epi::init('base','cache-memcached','session-apc');
/*
 * This is a sample page whch uses EpiCode.
 * There is a .htaccess file which uses mod_rewrite to redirect all requests to index.php while preserving GET parameters.
 * The $_['routes'] array defines all uris which are handled by EpiCode.
 * EpiCode traverses back along the path until it finds a matching page.
 *  i.e. If the uri is /foo/bar and only 'foo' is defined then it will execute that route's action.
 * It is highly recommended to define a default route of '' for the home page or root of the site (yoursite.com/).
 */
getRoute()->get('/', 'dbhandler');
getRoute()->run();
/*
 * ******************************************************************************************
 * Define functions and classes which are executed by EpiCode based on the $_['routes'] array
 * ******************************************************************************************
 */
function dbhandler()
{
    $users = getDatabase()->all('SELECT * FROM user');
    echo "<h2>All users</h2><ol>";
    foreach ($users as $key => $user) {
Example #6
0
 public function __construct($params)
 {
     parent::__construct();
     $this->db = EpiDatabase::getInstance('mysql', $params['database'], $params['host'], $params['username'], $params['password']);
     $this->table = $params['table'];
 }