本文整理汇总了PHP中PMF_Db::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP PMF_Db::factory方法的具体用法?PHP PMF_Db::factory怎么用?PHP PMF_Db::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMF_Db
的用法示例。
在下文中一共展示了PMF_Db::factory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startInstall
/**
* Starts the installation
*
* @param array $DB
*/
public function startInstall(array $DB = null)
{
$query = $uninst = $dbSetup = [];
// Check table prefix
$dbSetup['dbPrefix'] = $sqltblpre = PMF_Filter::filterInput(INPUT_POST, 'sqltblpre', FILTER_SANITIZE_STRING, '');
if ('' !== $dbSetup['dbPrefix']) {
PMF_Db::setTablePrefix($dbSetup['dbPrefix']);
}
// Check database entries
$dbSetup['dbType'] = PMF_Filter::filterInput(INPUT_POST, 'sql_type', FILTER_SANITIZE_STRING);
if (!is_null($dbSetup['dbType'])) {
$dbSetup['dbType'] = trim($dbSetup['dbType']);
if (!file_exists(PMF_ROOT_DIR . '/setup/assets/sql/' . $dbSetup['dbType'] . '.sql.php')) {
printf('<p class="alert alert-danger"><strong>Error:</strong> Invalid server type: %s</p>', $dbSetup['dbType']);
PMF_System::renderFooter(true);
}
} else {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please select a database type.</p>\n";
PMF_System::renderFooter(true);
}
$dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_server', FILTER_SANITIZE_STRING);
if (is_null($dbSetup['dbServer']) && !PMF_System::isSqlite($dbSetup['dbType'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database server.</p>\n";
PMF_System::renderFooter(true);
}
$dbSetup['dbPort'] = PMF_Filter::filterInput(INPUT_POST, 'sql_port', FILTER_VALIDATE_INT);
if (is_null($dbSetup['dbPort']) && !PMF_System::isSqlite($dbSetup['dbType'])) {
echo "<p class=\"alert alert-error\"><strong>Error:</strong> Please add a valid database port.</p>\n";
PMF_System::renderFooter(true);
}
$dbSetup['dbUser'] = PMF_Filter::filterInput(INPUT_POST, 'sql_user', FILTER_SANITIZE_STRING);
if (is_null($dbSetup['dbUser']) && !PMF_System::isSqlite($dbSetup['dbType'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database username.</p>\n";
PMF_System::renderFooter(true);
}
$dbSetup['dbPassword'] = PMF_Filter::filterInput(INPUT_POST, 'sql_passwort', FILTER_UNSAFE_RAW);
if (is_null($dbSetup['dbPassword']) && !PMF_System::isSqlite($dbSetup['dbType'])) {
// Password can be empty...
$dbSetup['dbPassword'] = '';
}
$dbSetup['dbDatabaseName'] = PMF_Filter::filterInput(INPUT_POST, 'sql_db', FILTER_SANITIZE_STRING);
if (is_null($dbSetup['dbDatabaseName']) && !PMF_System::isSqlite($dbSetup['dbType'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a database name.</p>\n";
PMF_System::renderFooter(true);
}
if (PMF_System::isSqlite($dbSetup['dbType'])) {
$dbSetup['dbServer'] = PMF_Filter::filterInput(INPUT_POST, 'sql_sqlitefile', FILTER_SANITIZE_STRING);
if (is_null($dbSetup['dbServer'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a SQLite database filename.</p>\n";
PMF_System::renderFooter(true);
}
}
// check database connection
PMF_Db::setTablePrefix($dbSetup['dbPrefix']);
$db = PMF_Db::factory($dbSetup['dbType']);
$db->connect($dbSetup['dbServer'], $dbSetup['dbUser'], $dbSetup['dbPassword'], $dbSetup['dbDatabaseName']);
if (!$db) {
printf("<p class=\"alert alert-danger\"><strong>DB Error:</strong> %s</p>\n", $db->error());
PMF_System::renderFooter(true);
}
$configuration = new PMF_Configuration($db);
// check LDAP if available
$ldapEnabled = PMF_Filter::filterInput(INPUT_POST, 'ldap_enabled', FILTER_SANITIZE_STRING);
if (extension_loaded('ldap') && !is_null($ldapEnabled)) {
$ldapSetup = [];
// check LDAP entries
$ldapSetup['ldapServer'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_server', FILTER_SANITIZE_STRING);
if (is_null($ldapSetup['ldapServer'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP server.</p>\n";
PMF_System::renderFooter(true);
}
$ldapSetup['ldapPort'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_port', FILTER_VALIDATE_INT);
if (is_null($ldapSetup['ldapPort'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP port.</p>\n";
PMF_System::renderFooter(true);
}
$ldapSetup['ldapBase'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_base', FILTER_SANITIZE_STRING);
if (is_null($ldapSetup['ldapBase'])) {
echo "<p class=\"alert alert-danger\"><strong>Error:</strong> Please add a LDAP base search DN.</p>\n";
PMF_System::renderFooter(true);
}
// LDAP User and LDAP password are optional
$ldapSetup['ldapUser'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_user', FILTER_SANITIZE_STRING, '');
$ldapSetup['ldapPassword'] = PMF_Filter::filterInput(INPUT_POST, 'ldap_password', FILTER_SANITIZE_STRING, '');
// check LDAP connection
require PMF_ROOT_DIR . "/inc/PMF/Ldap.php";
$ldap = new PMF_Ldap($configuration);
$ldap->connect($ldapSetup['ldapServer'], $ldapSetup['ldapPort'], $ldapSetup['ldapBase'], $ldapSetup['ldapUser'], $ldapSetup['ldapPassword']);
if (!$ldap) {
echo "<p class=\"alert alert-danger\"><strong>LDAP Error:</strong> " . $ldap->error() . "</p>\n";
PMF_System::renderFooter(true);
}
}
// check loginname
$loginname = PMF_Filter::filterInput(INPUT_POST, 'loginname', FILTER_SANITIZE_STRING);
//.........这里部分代码省略.........
示例2: UniversalClassLoader
// Setting up PSR-0 autoloader for Symfony Components
//
require PMF_INCLUDE_DIR . '/libs/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$loader = new UniversalClassLoader();
$loader->registerNamespace('Symfony', PMF_INCLUDE_DIR . '/libs');
$loader->registerPrefix('PMF_', PMF_INCLUDE_DIR);
$loader->register();
//
// Set the error handler to our pmf_error_handler() function
//
set_error_handler('pmf_error_handler');
//
// Create a database connection
//
PMF_Db::setTablePrefix($DB['prefix']);
$db = PMF_Db::factory($DB['type']);
$db->connect($DB['server'], $DB['user'], $DB['password'], $DB['db']);
//
// Fetch the configuration and add the database connection
//
$faqConfig = new PMF_Configuration($db);
$faqConfig->getAll();
//
// We always need a valid session!
//
ini_set('session.use_only_cookies', 1);
// Avoid any PHP version to move sessions on URLs
ini_set('session.auto_start', 0);
// Prevent error to use session_start() if it's active in php.ini
ini_set('session.use_trans_sid', 0);
ini_set('url_rewriter.tags', '');