本文整理汇总了PHP中DatabaseBase::newFromType方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::newFromType方法的具体用法?PHP DatabaseBase::newFromType怎么用?PHP DatabaseBase::newFromType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::newFromType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMasterDB
function getMasterDB()
{
if (!isset($this->dbConn)) {
$this->dbConn = DatabaseBase::newFromType($this->dbType, array('server' => $this->dbServer, 'user' => $this->dbUser, 'password' => $this->dbPassword, 'dbname' => $this->dbName, 'flags' => $this->dbFlags, 'tableprefix' => $this->tablePrefix));
}
return $this->dbConn;
}
示例2: initFromCond
private function initFromCond($cond)
{
global $wgExternalAuthConf;
$this->mDb = DatabaseBase::newFromType($wgExternalAuthConf['DBtype'], array('server' => $wgExternalAuthConf['DBserver'], 'user' => $wgExternalAuthConf['DBuser'], 'password' => $wgExternalAuthConf['DBpassword'], 'dbname' => $wgExternalAuthConf['DBname'], 'tableprefix' => $wgExternalAuthConf['DBprefix']));
$row = $this->mDb->selectRow('user', array('user_name', 'user_id', 'user_password', 'user_email', 'user_email_authenticated'), $cond, __METHOD__);
if (!$row) {
return false;
}
$this->mRow = $row;
return true;
}
示例3: foreach
$db_tables[$row[0]] = True;
}
// And check to see what indexes have already been created.
foreach ($db_indexes as $table => $idx){
$res = $dbr->query("show index from " . $table);
while ($row = $dbr->fetchRow($res)){
$db_indexes[$table][$row[2]] = True;
}
}
// We need root priveledges to do this.
$db_root = DatabaseBase::newFromType( $wgDBtype,
array(
'host' => $wgDBserver,
'user' => $dba,
'password' => $dba_pass,
'dbname' => $wgDBname
)
);
if (!$do_remove){
// Now do the actual creating of tables.
foreach ($create_scripts as $table => $scripts) {
if (!array_key_exists($table, $db_tables)){
foreach ($scripts as $script){
$db_root->query($script);
}
}
}
// Now do the actual creating of indexes.
foreach ($create_index_scripts as $table => $idxs){
示例4: getDBData
static function getDBData($dbID, $from, $columns, $where, $options)
{
global $edgDBServerType;
global $edgDBServer;
global $edgDBName;
global $edgDBUser;
global $edgDBPass;
global $edgDBFlags;
global $edgDBTablePrefix;
// Mandatory parameters
if (!array_key_exists($dbID, $edgDBServerType) || !array_key_exists($dbID, $edgDBServer) || !array_key_exists($dbID, $edgDBName) || !array_key_exists($dbID, $edgDBUser) || !array_key_exists($dbID, $edgDBPass)) {
echo wfMsgExt("externaldata-db-incomplete-information", array('parse', 'escape'));
return;
}
$db_type = $edgDBServerType[$dbID];
$db_server = $edgDBServer[$dbID];
$db_name = $edgDBName[$dbID];
$db_username = $edgDBUser[$dbID];
$db_password = $edgDBPass[$dbID];
// Optional parameters
if (array_key_exists($dbID, $edgDBFlags)) {
$db_flags = $edgDBFlags[$dbID];
} else {
$db_flags = DBO_DEFAULT;
}
if (array_key_exists($dbID, $edgDBTablePrefix)) {
$db_tableprefix = $edgDBTablePrefix[$dbID];
} else {
$db_tableprefix = '';
}
// DatabaseBase::newFromType() was added in MW 1.17 - it was
// then replaced by DatabaseBase::factory() in MW 1.18
$factorFunction = array('DatabaseBase', 'factory');
$newFromTypeFunction = array('DatabaseBase', 'newFromType');
if (is_callable($factorFunction)) {
$db = DatabaseBase::factory($db_type, array('host' => $db_server, 'user' => $db_username, 'password' => $db_password, 'dbname' => $db_name, 'dbName' => $db_name, 'flags' => $db_flags, 'tablePrefix' => $db_tableprefix));
} elseif (is_callable($newFromTypeFunction)) {
$db = DatabaseBase::newFromType($db_type, array('host' => $db_server, 'user' => $db_username, 'password' => $db_password, 'dbname' => $db_name, 'flags' => $db_flags, 'tableprefix' => $db_tableprefix));
} else {
if ($db_flags !== DBO_DEFAULT || $db_tableprefix !== '') {
print wfMsg("externaldata-db-option-unsupported", '<code>$edgDBFlags</code>', '<code>$edgDBTablePrefix</code>');
return;
}
if ($db_type == "mysql") {
$db = new Database($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "postgres") {
$db = new DatabasePostgres($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "mssql") {
$db = new DatabaseMssql($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "oracle") {
$db = new DatabaseOracle($db_server, $db_username, $db_password, $db_name);
} else {
$db = null;
}
}
if ($db == null) {
echo wfMsgExt("externaldata-db-unknown-type", array('parse', 'escape'));
return;
}
if (!$db->isOpen()) {
echo wfMsgExt("externaldata-db-could-not-connect", array('parse', 'escape'));
return;
}
if (count($columns) == 0) {
echo wfMsgExt("externaldata-db-no-return-values", array('parse', 'escape'));
return;
}
$rows = self::searchDB($db, $from, $columns, $where, $options);
$db->close();
$values = array();
foreach ($rows as $row) {
foreach ($columns as $column) {
$values[$column][] = $row[$column];
}
}
return $values;
}
示例5: getDBData
static function getDBData($dbID, $from, $columns, $where, $options)
{
global $edgDBServerType;
global $edgDBServer;
global $edgDBDirectory;
global $edgDBName;
global $edgDBUser;
global $edgDBPass;
global $edgDBFlags;
global $edgDBTablePrefix;
// Get all possible parameters
$db_type = self::getArrayValue($edgDBServerType, $dbID);
$db_server = self::getArrayValue($edgDBServer, $dbID);
$db_directory = self::getArrayValue($edgDBDirectory, $dbID);
$db_name = self::getArrayValue($edgDBName, $dbID);
$db_username = self::getArrayValue($edgDBUser, $dbID);
$db_password = self::getArrayValue($edgDBPass, $dbID);
$db_flags = self::getArrayValue($edgDBFlags, $dbID);
$db_tableprefix = self::getArrayValue($edgDBTablePrefix, $dbID);
// Validate parameters
if ($db_type == '') {
echo wfMsgExt("externaldata-db-incomplete-information", array('parse', 'escape'));
return;
} elseif ($db_type == 'sqlite') {
if ($db_directory == '' || $db_name == '') {
echo wfMsgExt("externaldata-db-incomplete-information", array('parse', 'escape'));
return;
}
} else {
if ($db_server == '' || $db_name == '' || $db_username == '' || $db_password == '') {
echo wfMsgExt("externaldata-db-incomplete-information", array('parse', 'escape'));
return;
}
}
// Additional settings
if ($db_type == 'sqlite') {
global $wgSQLiteDataDir;
$oldDataDir = $wgSQLiteDataDir;
$wgSQLiteDataDir = $db_directory;
}
if ($db_flags == '') {
$db_flags = DBO_DEFAULT;
}
// DatabaseBase::newFromType() was added in MW 1.17 - it was
// then replaced by DatabaseBase::factory() in MW 1.18
$factoryFunction = array('DatabaseBase', 'factory');
$newFromTypeFunction = array('DatabaseBase', 'newFromType');
if (is_callable($factoryFunction)) {
$db = DatabaseBase::factory($db_type, array('host' => $db_server, 'user' => $db_username, 'password' => $db_password, 'dbname' => $db_name, 'dbName' => $db_name, 'flags' => $db_flags, 'tablePrefix' => $db_tableprefix));
} elseif (is_callable($newFromTypeFunction)) {
$db = DatabaseBase::newFromType($db_type, array('host' => $db_server, 'user' => $db_username, 'password' => $db_password, 'dbname' => $db_name, 'flags' => $db_flags, 'tableprefix' => $db_tableprefix));
} else {
if ($db_flags !== DBO_DEFAULT || $db_tableprefix !== '') {
print wfMsg("externaldata-db-option-unsupported", '<code>$edgDBFlags</code>', '<code>$edgDBTablePrefix</code>');
return;
}
if ($db_type == "mysql") {
$db = new Database($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "postgres") {
$db = new DatabasePostgres($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "mssql") {
$db = new DatabaseMssql($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "oracle") {
$db = new DatabaseOracle($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "sqlite") {
$db = new DatabaseSqlite($db_server, $db_username, $db_password, $db_name);
} elseif ($db_type == "db2") {
$db = new DatabaseIbm_db2($db_server, $db_username, $db_password, $db_name);
} else {
$db = null;
}
}
if ($db == null) {
echo wfMsgExt("externaldata-db-unknown-type", array('parse', 'escape'));
return;
}
if (!$db->isOpen()) {
echo wfMsgExt("externaldata-db-could-not-connect", array('parse', 'escape'));
return;
}
if (count($columns) == 0) {
echo wfMsgExt("externaldata-db-no-return-values", array('parse', 'escape'));
return;
}
$rows = self::searchDB($db, $from, $columns, $where, $options);
$db->close();
if ($db_type == 'sqlite') {
// Reset global variable back to its original value.
global $wgSQLiteDataDir;
$wgSQLiteDataDir = $oldDataDir;
}
$values = array();
foreach ($rows as $row) {
foreach ($columns as $column) {
$values[$column][] = $row[$column];
}
}
return $values;
}
示例6: doSubmit
function doSubmit()
{
global $wgOut, $wgUser, $wgServer, $wgLang, $wgContLang;
global $wgDBserver, $wgDBsqluser, $wgDBsqlpassword, $wgDBname, $wgSqlTimeout;
global $wgDBtype;
# Use a limit, folks!
$this->query = trim($this->query);
if (preg_match('/^SELECT/i', $this->query) && !preg_match('/LIMIT/i', $this->query)) {
$this->query .= ' LIMIT 100';
}
$conn = DatabaseBase::newFromType($wgDBtype, array('host' => $wgDBserver, 'user' => $wgDBsqluser, 'password' => $wgDBsqlpassword, 'dbname' => $wgDBname));
$this->logQuery($this->query);
# Start timer, will kill the DB thread in $wgSqlTimeout seconds
# FIXME: timer functions needed!
# $conn->startTimer( $wgSqlTimeout );
$res = $conn->query($this->query, 'SpecialAsksql::doSubmit');
# $conn->stopTimer();
$this->logFinishedQuery();
$n = 0;
@($n = $conn->numFields($res));
$titleList = false;
if ($n) {
$k = array();
for ($x = 0; $x < $n; ++$x) {
array_push($k, $conn->fieldName($res, $x));
}
if ($n == 2 && in_array('page_title', $k) && in_array('page_namespace', $k)) {
$titleList = true;
}
$a = array();
foreach ($res as $s) {
array_push($a, $s);
}
$conn->freeResult($res);
if ($titleList) {
$r = "";
foreach ($a as $y) {
$sTitle = htmlspecialchars($y->page_title);
if ($y->page_namespace) {
$sNamespace = $wgContLang->getNsText($y->page_namespace);
$link = "{$sNamespace}:{$sTitle}";
} else {
$link = "{$sTitle}";
}
$title = Title::newFromText($link);
$skin = $wgUser->getSkin();
$link = $skin->makeLinkObj($title);
$r .= "* [[{$link}]]<br />\n";
}
} else {
$r = "<table border=1 bordercolor=black cellspacing=0 " . "cellpadding=2><tr>\n";
foreach ($k as $x) {
$r .= "<th>" . htmlspecialchars($x) . "</th>";
}
$r .= "</tr>\n";
foreach ($a as $y) {
$r .= '<tr>';
foreach ($k as $x) {
$o = $y->{$x};
if ($x == 'page_title' or $x == 'rc_title') {
$namespace = 0;
if ($x == 'page_title' && isset($y->page_namespace)) {
$namespace = $y->page_namespace;
}
if ($x == 'rc_title' && isset($y->rc_namespace)) {
$namespace = $y->rc_namespace;
}
$title =& Title::makeTitle($namespace, $o);
$o = "<a href=\"" . $title->escapeLocalUrl() . "\" class='internal'>" . htmlspecialchars($y->{$x}) . '</a>';
} else {
$o = htmlspecialchars($o);
}
$r .= '<td>' . $o . "</td>\n";
}
$r .= "</tr>\n";
}
$r .= "</table>\n";
}
}
$this->showForm(wfMsg("querysuccessful"));
$wgOut->addHTML("<hr />{$r}\n");
}
示例7: execute
public function execute()
{
if ($this->getVar('_ExistingDBSettings')) {
return 'skip';
}
$r = $this->parent->request;
if ($r->wasPosted()) {
$status = $this->submit();
if ($status->isGood()) {
$this->setVar('_UpgradeDone', false);
return 'continue';
} else {
$this->parent->showStatusBox($status);
}
}
$this->startForm();
$types = "<ul class=\"config-settings-block\">\n";
$settings = '';
$defaultType = $this->getVar('wgDBtype');
$dbSupport = '';
foreach ($this->parent->getDBTypes() as $type) {
$link = DatabaseBase::newFromType($type)->getSoftwareLink();
$dbSupport .= wfMsgNoTrans("config-support-{$type}", $link) . "\n";
}
$this->addHTML($this->parent->getInfoBox(wfMsg('config-support-info', $dbSupport)));
foreach ($this->parent->getVar('_CompiledDBs') as $type) {
$installer = $this->parent->getDBInstaller($type);
$types .= '<li>' . Xml::radioLabel($installer->getReadableName(), 'DBType', $type, "DBType_{$type}", $type == $defaultType, array('class' => 'dbRadio', 'rel' => "DB_wrapper_{$type}")) . "</li>\n";
$settings .= Html::openElement('div', array('id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper')) . Html::element('h3', array(), wfMsg('config-header-' . $type)) . $installer->getConnectForm() . "</div>\n";
}
$types .= "</ul><br clear=\"left\"/>\n";
$this->addHTML($this->parent->label('config-db-type', false, $types) . $settings);
$this->endForm();
}
示例8: reallyOpenConnection
/**
* Really opens a connection. Uncached.
* Returns a Database object whether or not the connection was successful.
* @access private
*/
function reallyOpenConnection($server, $dbNameOverride = false)
{
if (!is_array($server)) {
throw new MWException('You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.');
}
$host = $server['host'];
$dbname = $server['dbname'];
if ($dbNameOverride !== false) {
$server['dbname'] = $dbname = $dbNameOverride;
}
# Create object
wfDebug("Connecting to {$host} {$dbname}...\n");
try {
$db = DatabaseBase::newFromType($server['type'], $server);
} catch (DBConnectionError $e) {
// FIXME: This is probably the ugliest thing I have ever done to
// PHP. I'm half-expecting it to segfault, just out of disgust. -- TS
$db = $e->db;
}
if ($db->isOpen()) {
wfDebug("Connected to {$host} {$dbname}.\n");
} else {
wfDebug("Connection failed to {$host} {$dbname}.\n");
}
$db->setLBInfo($server);
if (isset($server['fakeSlaveLag'])) {
$db->setFakeSlaveLag($server['fakeSlaveLag']);
}
if (isset($server['fakeMaster'])) {
$db->setFakeMaster(true);
}
return $db;
}