Example #1
0
 public function setup()
 {
     //Setup session stuff
     SilkSession::setup();
     //Load up the configuration file
     if (is_file(join_path(ROOT_DIR, 'config', 'setup.yml'))) {
         $config = SilkYaml::load(join_path(ROOT_DIR, 'config', 'setup.yml'));
     } else {
         die("Config file not found!");
     }
     //Add class path entries
     if (isset($config['class_autoload'])) {
         foreach ($config['class_autoload'] as $dir) {
             add_class_directory(join_path(ROOT_DIR, $dir));
         }
     }
     //Setup the database connection
     if (!isset($config['database']['dsn'])) {
         die("No database information found in the configuration file");
     }
     if (null == SilkDatabase::connect($config['database']['dsn'], $config['debug'], true, $config['database']['prefix'])) {
         die("Could not connect to the database");
     }
     silk()->set('config', $config);
     //Load components
     SilkComponentManager::load();
 }
Example #2
0
/**
 * Returns the currently configured database prefix.
 *
 * @since 0.4
 */
function db_prefix()
{
    return SilkDatabase::get_prefix();
}
Example #3
0
 static function connect($dsn, $debug = false, $die = true, $prefix = null, $make_global = true)
 {
     /*
     $gCms = silk();
     $persistent = false;
     
     if ($dbms == '')
     {
     	$config = cms_config();
     	$dbms = $config['dbms'];
     	$hostname = $config['db_hostname'];
     	$username = $config['db_username'];
     	$password = $config['db_password'];
     	$dbname = $config['db_name'];
     	$debug = $config['debug'];
     	$persistent = $config['persistent_db_conn'];
     }
     */
     if ($prefix !== null) {
         self::$prefix = $prefix;
     }
     $dbinstance = null;
     $_GLOBALS['ADODB_CACHE_DIR'] = join_path(ROOT_DIR, 'tmp', 'cache');
     require_once join_path(SILK_LIB_DIR, 'adodb', 'adodb-exceptions.inc.php');
     require_once join_path(SILK_LIB_DIR, 'adodb', 'adodb.inc.php');
     try {
         $dbinstance = ADONewConnection($dsn);
         $dbinstance->fnExecute = 'count_execs';
         $dbinstance->fnCacheExecute = 'count_cached_execs';
     } catch (exception $e) {
         if ($die) {
             echo "<strong>Database Connection Failed</strong><br />";
             echo "Error: {$dbinstance->_errorMsg}<br />";
             echo "Function Performed: {$e->fn}<br />";
             echo "Host/DB: {$e->host}/{$e->database}<br />";
             die;
         } else {
             return null;
         }
     }
     $dbinstance->SetFetchMode(ADODB_FETCH_ASSOC);
     $dbinstance->debug = $debug;
     if (isset($dbms) && $dbms == 'sqlite') {
         $dbinstance->Execute("PRAGMA short_column_names = 1;");
         sqlite_create_function($dbinstance->_connectionID, 'now', 'time', 0);
     }
     if ($make_global) {
         self::$instance = $dbinstance;
     }
     //Initialize the CMS_DB_PREFIX define
     self::get_prefix();
     return $dbinstance;
 }
 function __destruct()
 {
     //*cough* Hack
     SilkDatabase::close();
 }
Example #5
0
 /**
  * Reports on the buffered marks
  *
  * @access public
  * @param string Glue string
  **/
 function report($memory = true, $database = true, $glue = '')
 {
     //$db = db();
     echo '<div id="profiler_output" style="font-size: .75em;">';
     echo implode($glue, $this->_buffer);
     if ($memory) {
         echo '<br />';
         echo $this->get_memory();
     }
     if ($database) {
         echo '<br />' . SilkDatabase::query_count() . ' queries executed';
     }
     echo '</div>';
 }