function actionDefault() { // Get the data $db = YDDatabase::getInstance('sqlite', 'database2.db'); // Output the server version YDDebugUtil::dump($db->getServerVersion(), 'Version:'); // Output some queries YDDebugUtil::dump($db->getRecords('select * from escalations'), 'escalations'); YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'sqlite_master'); YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_NUM); YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'array - sqlite_master'); YDConfig::set('YD_DB_FETCHTYPE', YD_DB_FETCH_ASSOC); // Test string escaping YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string'); // Show number of queries YDDebugUtil::dump($db->getSqlCount(), 'Number of queries'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )'); YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )'); YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )'); // Test limits YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10)); YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25)); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
function actionDefault() { // Get the data $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); $this->template->assign('processList', $db->getRecords('show processlist')); $this->template->assign('status', $db->getRecords('show status')); $this->template->assign('variables', $db->getRecords('show variables')); $this->template->assign('version', $db->getServerVersion()); $this->template->assign('sqlcount', $db->getSqlCount()); // Output the template $this->template->display(); // Test string escaping YDDebugUtil::dump($db->escape("Pieter's Framework"), '$db->escape'); YDDebugUtil::dump($db->prepareSql('SELECT * FROM comments WHERE id = :1 and author = :2', 1, "Pieter's Author"), '$db->prepareSql'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->escapeSql($db->getDate()), 'escapeSql( getDate() )'); YDDebugUtil::dump($db->escapeSql($db->getTime()), 'escapeSql( getTime() )'); YDDebugUtil::dump($db->escapeSql($db->getDate('__NOW__')), 'escapeSql( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->escapeSql($db->getTime('__NOW__')), 'escapeSql( getTime( \'__NOW__\' ) )'); // Test limits YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10)); YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 30)); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
function actionDefault() { // Get the database connections $db1 = YDDatabase::getInstance('mysql', 'ydweblog', 'root', '', 'localhost'); $db2 = YDDatabase::getInstance('oracle', 'creodb_directeur', 'prinergy', 'araxi'); $db3 = YDDatabase::getInstance('postgres', 'test_db', 'postgres', 'Ster4484', 'localhost'); $db4 = YDDatabase::getInstance('sqlite', 'db_metadata.db'); // Get the metadata $db1_meta = new YDDatabaseMetaData($db1); $db2_meta = new YDDatabaseMetaData($db2); $db3_meta = new YDDatabaseMetaData($db3); $db4_meta = new YDDatabaseMetaData($db4); // Get the list of tables YDDebugUtil::dump($db1_meta->getTables(), 'mysql - getTables'); YDDebugUtil::dump($db2_meta->getTables(), 'oracle - getTables'); YDDebugUtil::dump($db3_meta->getTables(), 'postgres - getTables'); YDDebugUtil::dump($db4_meta->getTables(), 'sqlite - getTables'); // Get the list of fields for a table YDDebugUtil::dump($db1_meta->getFields('ydw_items'), 'mysql - getFields'); YDDebugUtil::dump($db2_meta->getFields('dbcs_jacket'), 'oracle - getFields'); YDDebugUtil::dump($db3_meta->getFields(), 'postgres - getFields'); YDDebugUtil::dump($db4_meta->getFields('notes'), 'sqlite - getFields'); // Get the list of indexes for a table YDDebugUtil::dump($db1_meta->getIndexes('ydw_items'), 'mysql - getIndexes'); YDDebugUtil::dump($db2_meta->getIndexes('dbcs_jacket'), 'oracle - getIndexes'); YDDebugUtil::dump($db3_meta->getIndexes(), 'postgres - getIndexes'); YDDebugUtil::dump($db4_meta->getIndexes('notes'), 'sqlite - getIndexes'); }
function actionDefault() { // Get the data $db = YDDatabase::getInstance('sqlite', 'database2.db'); // Output the server version YDDebugUtil::dump($db->getServerVersion(), 'Version:'); // Output some queries YDDebugUtil::dump($db->getRecords('select * from escalations'), 'escalations'); YDDebugUtil::dump($db->getRecords('select * from sqlite_master'), 'sqlite_master'); // Test string escaping YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string'); // Show number of queries YDDebugUtil::dump($db->getSqlCount(), 'Number of queries'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )'); YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )'); YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )'); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
function actionDefault() { // Get the data $db = YDDatabase::getInstance('oracle', 'CREODB_STATLER', 'prinergy_rpt', 'prinergy_rpt'); // Output the server version YDDebugUtil::dump($db->getServerVersion(), 'Version:'); // Output some queries YDDebugUtil::dump($db->getRecords('select * from RPT_Customer_V'), 'RPT_Customer_V'); // Output some queries YDDebugUtil::dump($db->getValue('select sysdate from dual'), 'sysdate'); // Test string escaping YDDebugUtil::dump($db->escape("Pieter's Framework"), '$db->escape'); // Show number of queries YDDebugUtil::dump($db->getSqlCount(), 'Number of queries'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->escapeSql($db->getDate()), 'escapeSql( getDate() )'); YDDebugUtil::dump($db->escapeSql($db->getTime()), 'escapeSql( getTime() )'); YDDebugUtil::dump($db->escapeSql($db->getDate('__NOW__')), 'escapeSql( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->escapeSql($db->getTime('__NOW__')), 'escapeSql( getTime( \'__NOW__\' ) )'); // Test limits YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10)); YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25)); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
/** * Constructor. Set the database table name and necessary field names * * @param $table Name of the tree database table * @param $db (optional) The YDDatabase instance name or object pointing to the database * @param $idField (optional) Name of the primary key ID field. Default is id. * @param $parentField (optional) Name of the parent ID field. Default is parent_id. * @param $sortField (optional) Name of the field to sort data. */ function YDDatabaseTree2($table, $db = 'default', $idField = 'id', $parentField = 'parent_id', $sortField = 'parent_id ASC, position ASC') { $this->db = YDDatabase::getNamedInstance($db); $this->table = $table; $this->fields = array('id' => $idField, 'parent' => $parentField, 'lineage' => 'lineage', 'level' => 'level', 'position' => 'position'); $this->sortField = $sortField; }
function actionDefault() { // Get the data $db = YDDatabase::getInstance('postgres', 'template1', 'pieter', 'kermit', 'yellowduck'); // Output the server version YDDebugUtil::dump($db->getServerVersion(), 'Version:'); // Output some queries YDDebugUtil::dump($db->getRecords('select now()'), 'select now();'); // Test string escaping YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string'); // Show number of queries YDDebugUtil::dump($db->getSqlCount(), 'Number of queries'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )'); YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )'); YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )'); // Test limits YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10)); YDDebugUtil::dump($db->_prepareSqlForLimit('SELECT * FROM TABLE', 10, 25)); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
function actionDefault() { // Get the data $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); $this->setVar('processList', $db->getRecords('show processlist')); $this->setVar('status', $db->getRecords('show status')); $this->setVar('variables', $db->getRecords('show variables')); $this->setVar('version', $db->getServerVersion()); $this->setVar('sqlcount', $db->getSqlCount()); // Output the template $this->outputTemplate(); // Test string escaping YDDebugUtil::dump($db->string("Pieter's Framework"), '$db->string'); // Test timestamps YDDebugUtil::dump($db->getDate(), 'getDate()'); YDDebugUtil::dump($db->getTime(), 'getTime()'); YDDebugUtil::dump($db->getDate('__NOW__'), 'getDate( \'__NOW__\' )'); YDDebugUtil::dump($db->getTime('__NOW__'), 'getTime( \'__NOW__\' )'); YDDebugUtil::dump($db->getDate('28-FEB-1977'), 'getDate( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->getTime('28-FEB-1977'), 'getTime( \'28-FEB-1977\' )'); YDDebugUtil::dump($db->sqlString($db->getDate()), 'sqlString( getDate() )'); YDDebugUtil::dump($db->sqlString($db->getTime()), 'sqlString( getTime() )'); YDDebugUtil::dump($db->sqlString($db->getDate('__NOW__')), 'sqlString( getDate( \'__NOW__\' ) )'); YDDebugUtil::dump($db->sqlString($db->getTime('__NOW__')), 'sqlString( getTime( \'__NOW__\' ) )'); // Test errors YDDebugUtil::dump($db->getRecords('xx'), 'should return error'); // Close the database connection $db->close(); }
/** * Constructor. Set the database connection * * @param $db (optional) The YDDatabase object pointing to the database. If you use a null value, the default * database instance will be used (using YDDatabase::getNamedInstance()). */ function YDDatabaseMetaData($db = null) { if (is_null($db)) { $this->db = YDDatabase::getNamedInstance(); } else { $this->db = $db; } }
function database_backup() { $this->YDRequest(); // Get the data $this->db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); // Create the YDMysqlDump object $this->dump = new YDMysqlDump($this->db); }
/** * Constructor. Set the database table name and necessary field names * * @param $db The YDDatabase instance name or object pointing to the database * @param $table Name of the tree database table * @param $idField (optional) Name of the primary key ID field. Default is id. * @param $parentField (optional) Name of the parent ID field. Default is parent_id. * @param $sortField (optional) Name of the field to sort data. Default is position, title. */ function YDDatabaseTree($db = 'default', $table, $idField = 'id', $parentField = 'parent_id', $sortField = 'position, title') { $this->db = YDDatabase::getNamedInstance($db); $this->table = $table; $this->fields = array('id' => $idField, 'parent' => $parentField, 'sort' => $sortField, 'nleft' => 'nleft', 'nright' => 'nright', 'nlevel' => 'nlevel', 'position' => 'position'); $this->_use_query_cache = true; $this->_query_cache = array(); }
function index() { // Initialize the parent class $this->YDRequest(); // Initialize the template object $this->template = new YDTemplate(); // Make the database connection $this->db = YDDatabase::getInstance($GLOBALS['db']['type'], $GLOBALS['db']['name'], $GLOBALS['db']['user'], $GLOBALS['db']['pass'], $GLOBALS['db']['host']); }
function database_tree() { // Call the parent $this->YDRequest(); // Get the database connection $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost'); // Get the tree instance $this->tree = new YDDatabaseTree($db, 'nested_tree'); }
function database_objecttree() { // Call the parent $this->YDRequest(); // Get the database connection $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost'); // Get the tree instance $this->tree = new YDDatabaseObjectTree('nested_tree', $db); // register extra column $this->tree->registerField('title', true); }
function YDWeblogAPI() { // Initialize the parent $this->YDBase(); // Get the database connection $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost')); // Add any missing body_more field $fields = $this->db->getValuesByName('show fields from ' . YDConfig::get('db_prefix', '') . 'items', 'field'); if (!in_array('body_more', $fields)) { $this->db->executeSql('ALTER TABLE ' . YDConfig::get('db_prefix', '') . 'items ADD body_more LONGTEXT AFTER body'); } }
function database_tree() { // Call the parent $this->YDRequest(); // Get the database connection $db = YDDatabase::getInstance('mysql', 'tree_test', 'root', '', 'localhost'); // Get the tree instance $this->tree = new YDDatabaseTree($db, 'nested_tree'); // Add some fields $this->tree->addField('t2.category'); // Add a join table $this->tree->addJoinTable('JOIN category t2 ON t1.cat_id = t2.id'); }
function actionDefault() { // Get the database connection $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); // Get the records $recordset = $db->getRecords('show status'); // Close the database connection $db->close(); // Create the YDRecordSet object $recordset = new YDRecordSet($recordset, -1, null); // Setup the template $this->template->assign('recordset', $recordset); // Display the template $this->template->display(); }
function actionDefault() { // Check if the template is cached if (!$this->tpl->is_cached(YD_SELF_SCRIPT)) { // Make some extensive database calls $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); $db->connect(); $this->tpl->assign('processList', $db->getRecords('show processlist')); $this->tpl->assign('status', $db->getRecords('show status')); $this->tpl->assign('variables', $db->getRecords('show variables')); $this->tpl->assign('version', $db->getServerVersion()); $this->tpl->assign('sqlcount', $db->getSqlCount()); // Indicate the template was not cached echo 'not cached'; } // Display the template $this->tpl->display('tplcache.tpl', YD_SELF_SCRIPT); }
function actionDefault() { // Get the pagesize and current page from the query string $page = @$_GET['page']; $size = @$_GET['size']; // Get the database connection $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); // Get the records $recordset = $db->getRecords('show status'); // Close the database connection $db->close(); // Create the YDRecordSet object $recordset = new YDRecordSet($recordset, $page, $size); // Setup the template $this->template->assign('recordset', $recordset); // Display the template $this->template->display(); }
function index() { // Initialize the parent class $this->YDRequest(); // Make the database connection $this->db = YDDatabase::getInstance($GLOBALS['db']['type'], $GLOBALS['db']['name'], $GLOBALS['db']['user'], $GLOBALS['db']['pass'], $GLOBALS['db']['host']); // Create the add form $this->form = new YDForm('addEntryForm'); // Add the elements $this->form->addElement('text', 'notetitle', 'Title:'); $this->form->addElement('textarea', 'notecontents', 'Contents:'); $this->form->addElement('submit', '_cmdSubmit', 'Save'); // Apply filters $this->form->addFilter('NoteTitle', 'trim'); $this->form->addFilter('NoteContents', 'trim'); // Add a rule $this->form->addRule('notetitle', 'required', 'Title is required'); $this->form->addRule('notecontents', 'required', 'Contents is required'); }
function actionDefault() { // Register the named instances YDDatabase::registerInstance('default', 'mysql', 'ydweblog', 'root', '', 'localhost'); YDDatabase::registerInstance('db_mysql', 'mysql', 'mysql', 'root', '', 'localhost'); YDDatabase::registerInstance('db_test', 'mysql', 'test', 'root', '', 'localhost'); // Get the default instance $db1 = YDDatabase::getNamedInstance(); YDDebugUtil::dump($db1, 'default instance, no name given'); // Get the default instance using it's name $db1 = YDDatabase::getNamedInstance('DEFAULT'); YDDebugUtil::dump($db1, 'default instance, using name'); // Get the db_mysql instance using it's name $db1 = YDDatabase::getNamedInstance('db_mysql'); YDDebugUtil::dump($db1, 'db_mysql instance'); // Get the db_bba_v2 instance using it's name $db1 = YDDatabase::getNamedInstance('db_test'); YDDebugUtil::dump($db1, 'db_test instance'); }
function actionDefault() { // Get the pagesize and current page from the query string $page = @$_GET['page']; $size = @$_GET['size']; // Get the database connection $db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); // Get the records $recordset = $db->getRecordsAsSet('show status', $page, $size); // Alter the URL $url =& $recordset->getUrl(); $url->setQueryVar('test', 'val'); // Close the database connection $db->close(); // Setup the template $this->template->assign('recordset', $recordset); // Display the template $this->template->display(); }
function YDWeblogAPI() { // Initialize the parent $this->YDBase(); // Get the database connection $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost')); // Add any missing body_more field $fields = $this->db->getValuesByName('show fields from #_items', 'field'); if (!in_array('body_more', $fields)) { $this->db->executeSql('ALTER TABLE #_items ADD body_more LONGTEXT AFTER body'); } // Get the list of indexes $indexes = $this->db->getValuesByName('show keys from #_users', 'key_name'); if (in_array('email', $indexes)) { $this->db->executeSql('ALTER TABLE #_users DROP INDEX email'); } if (!in_array('name', $indexes)) { $this->db->executeSql('ALTER TABLE #_users ADD UNIQUE name (name)'); } }
/** * Class constructor for the YDMysqlDump class. * * @param $dbinstance Database instance name or object. */ function YDMysqlDump($dbinstance = 'default') { // Initializes YDBase $this->YDAddOnModule(); // Setup the module $this->_author = 'Francisco Azevedo'; $this->_version = '1.3'; $this->_copyright = '(c) 2005 Francisco Azevedo, francisco@fusemail.com'; $this->_description = 'This class defines a mysql backup/restore system.'; // database instance $this->dbinstance = YDDatabase::getNamedInstance($dbinstance); // predefined filepath for store content (used if we don't want a string) $this->filepath = YD_DIR_TEMP . '/backup.sql'; // defaults $this->useComments = false; $this->useDrops = false; $this->useStructure = false; $this->useData = false; // custom tables $this->tables_to_use = null; $this->tables_to_ignore = null; }
} } // Include the standard modules YDInclude('YDUrl.php'); YDInclude('YDUtil.php'); YDInclude('YDForm.php'); YDInclude('YDBBCode.php'); YDInclude('YDTemplate.php'); YDInclude('YDDatabase.php'); YDInclude('YDFileSystem.php'); YDInclude('YDFormElements/YDFormElement_BBTextArea.php'); // Include other libraries YDInclude(dirname(__FILE__) . '/YDWeblogAPI.php'); YDInclude(dirname(__FILE__) . '/YDWeblogRequest.php'); // Check if the weblog application is locked or not $db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost')); $tables = $db->getRecords('show tables'); $table_field_name = 'tables_in_' . strtolower(YDConfig::get('db_name', 'YDWeblog')); foreach ($tables as $table) { if (strtolower($table[$table_field_name]) == YDConfig::get('db_prefix', '') . 'locked') { die('Weblog application is being updated. Please come again later.'); } } // Set the right locale $language = YDConfig::get('weblog_language', 'en'); $language = empty($language) ? 'en' : $language; YDLocale::set($language); // The t function used for translations function t($t) { // Return empty string when param is missing
function setDatabase() { $this->__db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost'); }
/** * Using this static function, you can get an instance of a YDDatabaseDriver class. * * @param $driver Name of the database driver or array containing drivername, file name and class name. * @param $db Database name to use for the connection. * @param $user (optional) User name to use for the connection. * @param $pass (optional) Password to use for the connection. * @param $host (optional) Host name to use for the connection. * * @returns An instance of YDDatabaseDriver * * @static */ function getInstance($driver, $db, $user = '', $pass = '', $host = '') { // The list of known drivers $regDrivers = array(); // Register new driver if (is_array($driver) && isset($driver['drivername'])) { // Register a new driver $regDrivers[strtolower($driver['drivername'])] = $driver; $driver = $driver['drivername']; } else { // Get the standard driver list $regDrivers = YDDatabase::getSupportedDrivers(); // Check if the driver exists if (!array_key_exists(strtolower($driver), $regDrivers)) { trigger_error('Unsupported database type: "' . $driver . '".', YD_ERROR); } } // Include the driver if (!empty($regDrivers[strtolower($driver)]['file'])) { if (is_file($regDrivers[strtolower($driver)]['file'])) { include_once $regDrivers[strtolower($driver)]['file']; } else { include_once dirname(__FILE__) . '/YDDatabaseDrivers/' . $regDrivers[strtolower($driver)]['file']; } } // Check if the driver is supported if (!call_user_func(array($regDrivers[strtolower($driver)]['class'], 'isSupported'))) { trigger_error('Unsupported database type: "' . $driver . '". Extension is not loaded.', YD_ERROR); } // Make a new connection object and return it $className = $regDrivers[strtolower($driver)]['class']; return new $className($db, $user, $pass, $host); }
<?php // initialize the Yellow Duck Framework include_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php'; YDInclude('YDDatabase.php'); YDInclude('YDUrl.php'); // BASIC CONFIGURATION: set YDDatabase instance connection YDDatabase::registerInstance('default', 'mysql', 'xpto', 'root', '', 'localhost'); // BASIC CONFIGURATION: set portal language. Currently you can use 'en' and 'pt'. YDLocale::set('en'); // set admin template path YDConfig::set('YDCMTEMPLATES_ADMIN_PATH', dirname(__FILE__) . '/backend/templates'); YDConfig::set('YDCMTEMPLATES_ADMIN_URL', YDUrl::makeLinkAbsolute('./templates'));
function YDWeblogAPI() { // Initialize the parent $this->YDBase(); // Get the database connection $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost')); // Get a link to the database metadata $this->dbmeta = new YDDatabaseMetaData($this->db); // Upgrade the schema if needed $this->upgradeSchemaIfNeeded(); // The array that will hold the image metadata $this->imagemetadata = null; // Delete spam comments older than 7 days $sql = 'DELETE FROM #_comments WHERE is_spam = 1 AND created < (unix_timestamp()-604800)'; $this->db->executeSql($sql); // Delete the old IP numbers from spam check $comment_interval = YDConfig::get('comment_interval', 10); if ($comment_interval != '' && is_numeric($comment_interval)) { $sql = 'DELETE FROM #_spamcheck WHERE lastvisit < (unix_timestamp()-' . $comment_interval . ')'; $this->db->executeSql($sql); } // Cleanup the bad behaviour table part 1 $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 1 day ) < DATE_SUB( CURDATE(), INTERVAL 1 day ) AND request_method = \'GET\' AND `key` = \'00000000\''; $this->db->executeSql($sql); // Cleanup the bad behaviour table part 2 $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 7 day ) < DATE_SUB( CURDATE(), INTERVAL 7 day )'; $this->db->executeSql($sql); // Check against akismet if a key is there if (YDConfig::get('akismet_key', '') != '') { // Include the YDAkismet addon include_once YD_DIR_HOME_ADD . '/YDAkismet/YDAkismet.php'; // Get the URL of the weblog $weblog_url = dirname(YDRequest::getCurrentUrl(true)) . '/'; // Initialize YDAkismet $this->akismet = new YDAkismet($weblog_url, YDConfig::get('akismet_key', '')); } else { // No akismet $this->akismet = null; } }
/** * This function initializes the SimpleCMS package. It performs the following items: * - Create a new global array under $GLOBALS['YD_SIMPLECMS'] * - Adds a database connection under $GLOBALS['YD_SIMPLECMS']['db'] * - Adds a language array under $GLOBALS['YD_SIMPLECMS']['languages'] * - Adds a module manager instance under $GLOBALS['YD_SIMPLECMS']['moduleManager'] * - Adds a array under $GLOBALS['YD_SIMPLECMS']['adminMenu'] to keep track of the admin menu * - Adds a null value under $GLOBALS['YD_SIMPLECMS']['user'] to keep track of the current user * - Stores the current scope in $GLOBALS['YD_SIMPLECMS']['scope'] * * Even if you call this function multiple times, the initialization will only be done once. * * @todo * Negotiate the language and put it as an array under $GLOBALS['YD_SIMPLECMS']['languages'] * * @todo * Language settings should be specific for each scope * * @static */ function initialize() { // Check if the initialization is already done or not if (!isset($GLOBALS[YD_SIMPLECMS_PACKAGE_NAME]) || !is_array($GLOBALS[YD_SIMPLECMS_PACKAGE_NAME])) { // Create the array $GLOBALS[YD_SIMPLECMS_PACKAGE_NAME] = array(); $settings =& $GLOBALS[YD_SIMPLECMS_PACKAGE_NAME]; // Setup the database connection YDConfig::set('YD_DB_TABLEPREFIX', YDConfig::get('db_prefix')); $settings['db'] = YDDatabase::getInstance('mysql', YDConfig::get('db_name'), YDConfig::get('db_user'), YDConfig::get('db_pass'), YDConfig::get('db_host')); // The global list with admin menu $settings['adminMenu'] = array(); // The current user $settings['currentUser'] = null; // The module manager instance $settings['moduleManager'] = new YDSimpleCMSModuleManager(); $settings['moduleManager']->loadAllModules(); // Set the default scope $settings['scope'] = YD_SIMPLECMS_SCOPE_PUBLIC; // Get the site Id $settings['siteId'] = YDConfig::get('YD_SIMPLECMS_SITEID', 'SAMPLESITE'); // Create a browser information object $settings['browserInfo'] = new YDBrowserInfo(); $browserInfo =& $settings['browserInfo']; // // -- Negotiate the language -- // // Set the list of languages and the default language // $language = YDConfig::get( 'site_default_lang', '' ); // $languages = array(); // // // Get the current URL // $url = new YDUrl( YDRequest::getNormalizedCurrentUrl() ); // // // Get the list of languages // foreach ( array_slice( YDConfig::get( 'site_languages', array() ), 0, 4 ) as $key=>$lang ) { // if ( ! empty( $lang[0] ) ) { // $lang[0] = strtolower( $lang[0] ); // $url->setQueryVar( 'lang', $lang[0] ); // $languages[ $lang[0] ] = array( // 'name' => $lang[1], 'idx' => $key + 1, 'code' => $lang[0], 'url' => $url->getUrl(), // ); // } // } // // // Get the current language // $languages = array_keys( $languages ); // $lang = $browserInfo->getLanguage( $languages ); // $languageCookieName = YD_SIMPLECMS_PACKAGE_NAME . '_' . YDSimpleCms::getSiteId() . '_LANG'; // if ( YDRequest::getCookie( $languageCookieName, '', $languages ) != '' ) { // $lang = YDRequest::getCookie( $languageCookieName, '', $languages ); // } // //if ( $this->getQueryStringParameter( 'lang', '', $languages ) != '' ) { // // $lang = $this->getQueryStringParameter( 'lang', '', $languages ); // //} // $lang = strtolower( $lang ); // // // Set the right locale // YDLocale::set( $lang ); // // //YDDebugUtil::dump( $language, 'language' ); //YDDebugUtil::dump( $languages, 'languages' ); } }