本文整理汇总了PHP中Database::newDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::newDB方法的具体用法?PHP Database::newDB怎么用?PHP Database::newDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::newDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: election_install
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function election_install(&$content)
{
$db = Database::newDB();
$db->begin();
try {
$election = new \election\Resource\Election();
$election->createTable($db);
$single = new \election\Resource\Single();
$single->createTable($db);
$multiple = new \election\Resource\Multiple();
$multiple->createTable($db);
$candidate = new \election\Resource\Candidate();
$candidate->createTable($db);
$referendum = new \election\Resource\Referendum();
$referendum->createTable($db);
$ticket = new \election\Resource\Ticket();
$ticket->createTable($db);
} catch (\Exception $e) {
$db->buildTable($election->getTable())->drop(true);
$db->buildTable($single->getTable())->drop(true);
$db->buildTable($multiple->getTable())->drop(true);
$db->buildTable($candidate->getTable())->drop(true);
$db->buildTable($referendum->getTable())->drop(true);
$db->buildTable($ticket->getTable())->drop(true);
$db->rollback();
throw $e;
}
$db->commit();
$content[] = 'Tables created';
return true;
}
示例2: tailgate_install
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function tailgate_install(&$content)
{
$db = Database::newDB();
$db->begin();
try {
$game = new \tailgate\Resource\Game();
$t1 = $game->createTable($db);
$lot = new \tailgate\Resource\Lot();
$t2 = $lot->createTable($db);
$lottery = new \tailgate\Resource\Lottery();
$t3 = $lottery->createTable($db);
$spot = new \tailgate\Resource\Spot();
$t4 = $spot->createTable($db);
$student = new \tailgate\Resource\Student();
$t5 = $student->createTable($db);
$visitor = new \tailgate\Resource\Visitor();
$t6 = $visitor->createTable($db);
} catch (\Exception $e) {
$db->buildTable('tg_game')->drop(true);
$db->buildTable('tg_lot')->drop(true);
$db->buildTable('tg_lottery')->drop(true);
$db->buildTable('tg_spot')->drop(true);
$db->buildTable('tg_student')->drop(true);
$db->buildTable('tg_visitor')->drop(true);
$db->rollback();
throw $e;
}
$db->commit();
$content[] = 'Tables created';
return true;
}
示例3: pulse_uninstall
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function pulse_uninstall(&$content)
{
$content[] = 'Dropping schedule table.';
$db = Database::newDB();
$t1 = $db->addTable('pulse_schedule');
$t1->drop();
return true;
}
示例4: select
public function select()
{
foreach ($this->db_stack as $db) {
$query[] = $db->selectQuery();
}
$f_query = '(' . implode(') UNION (', $query) . ')';
$qdb = \Database::newDB();
$qdb->loadStatement($f_query);
return $qdb->fetchAll();
}
示例5: tailgate_uninstall
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function tailgate_uninstall(&$content)
{
$db = Database::newDB();
$db->buildTable('tg_game')->drop(true);
$db->buildTable('tg_lot')->drop(true);
$db->buildTable('tg_lottery')->drop(true);
$db->buildTable('tg_spot')->drop(true);
$db->buildTable('tg_student')->drop(true);
$db->buildTable('tg_visitor')->drop(true);
return true;
}
示例6: pullFolderRows
/**
* Pulls folders from the database according to folder type
* @param integer $ftype Folder type (image, document, multimedia)
* @return array
*/
protected function pullFolderRows()
{
if (!$this->ftype) {
throw new \Exception('Missing folder type');
}
$db = \Database::newDB();
$f = $db->addTable('folders');
$f->addFieldConditional('ftype', $this->ftype);
$f->addOrderBy('title');
$result = $db->select();
return $result;
}
示例7: election_uninstall
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function election_uninstall(&$content)
{
$db = Database::newDB();
$db->buildTable('elect_candidate')->drop(true);
$db->buildTable('elect_election')->drop(true);
$db->buildTable('elect_multiple')->drop(true);
$db->buildTable('elect_multi_chair_vote')->drop(true);
$db->buildTable('elect_referendum')->drop(true);
$db->buildTable('elect_referendum_vote')->drop(true);
$db->buildTable('elect_single')->drop(true);
$db->buildTable('elect_single_chair_vote')->drop(true);
$db->buildTable('elect_ticket')->drop(true);
$db->buildTable('elect_vote_complete')->drop(true);
return true;
}
示例8: printFile
public function printFile($id)
{
$db = \Database::newDB();
$t = $db->addTable('documents');
$t->addFieldConditional('id', (int) $id);
$row = $db->selectOneRow();
if (empty($row)) {
return null;
}
$template = new \Template();
$template->setModuleTemplate('filecabinet', 'FC_Forms/document_view.html');
$template->add('title', $row['title']);
$template->add('filepath', './filecabinet/' . $row['id']);
return $template->get();
}
示例9: execute
public static function execute()
{
session_start();
PHPWS_Core::initModClass('hms', 'Term.php');
PHPWS_Core::initModClass('hms', 'StudentFactory.php');
PHPWS_Core::initModClass('users', 'Users.php');
PHPWS_Core::initModClass('users', 'Current_User.php');
PHPWS_Core::initModClass('hms', 'UserStatus.php');
$errors = null;
$term = Term::getSelectedTerm();
$db1 = Database::newDB();
$t1 = $db1->addTable('hms_new_application');
$t1->addFieldConditional('term', $term);
$t1->addField('username');
$db2 = Database::newDB();
$t2 = $db2->addTable('hms_assignment');
$t2->addFieldConditional('term', $term);
$t2->addField('asu_username');
$union = new \Database\Union(array($db1, $db2));
$result = $union->select();
if (empty($result)) {
return 'No assignments or applications. Check your database.';
}
$count = 0;
$error_count = 0;
$_SESSION['User'] = new PHPWS_User();
$_SESSION['User']->username = 'nightlycache';
$_SESSION['User']->display_name = 'Nightly Cache';
foreach ($result as $row) {
$count++;
try {
//asking for the student updates the cache since the ttl is zero
StudentFactory::getStudentByUsername($row['username'], $term);
} catch (Exception $e) {
$errors[] = $e->getMessage() . "\n";
$error_count++;
}
if ($error_count >= HMS_CACHE_ERROR_THRESHOLD) {
throw new \Exception(HMS_CACHE_ERROR_THRESHOLD . ' errors occurred. Shutting down cache prematurely.');
}
}
$message = "{$count} student records cached.\n";
if (!empty($errors)) {
$message .= "Errors occurred:\n";
$message .= implode("\n", $errors);
}
return $message;
}
示例10: printFile
public function printFile($id)
{
$db = \Database::newDB();
$t = $db->addTable('images');
$t->addFieldConditional('id', (int) $id);
$row = $db->selectOneRow();
if (empty($row)) {
return null;
}
$template = new \Template();
$template->setModuleTemplate('filecabinet', 'FC_Forms/image_view.html');
$template->add('title', $row['title']);
$template->add('alt', $row['alt']);
$template->add('filepath', $row['file_directory'] . $row['file_name']);
return $template->get();
}
示例11: printFile
public function printFile($id)
{
$db = \Database::newDB();
$t = $db->addTable('multimedia');
$t->addFieldConditional('id', (int) $id);
$row = $db->selectOneRow();
if (empty($row)) {
return null;
}
$ext = \PHPWS_File::getFileExtension($row['file_name']);
if ($ext == 'mp3') {
$template = 'filters/audio.tpl';
} else {
$template = 'filters/media.tpl';
}
return \PHPWS_Template::process(array('FILE_PATH' => $row['file_directory'] . $row['file_name']), 'filecabinet', $template);
}
示例12: userNameSearch
/**
* Searches for suggestions based on username. If an exact match is found, then return
* a student object. Otherwise return false.
*/
private function userNameSearch($string)
{
$db = \Database::newDB();
$pdo = $db->getPDO();
$stmt = $pdo->prepare("SELECT * FROM intern_student_autocomplete WHERE username = :username");
$stmt->execute(array('username' => $string));
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result === false) {
return false;
}
$students = array();
try {
$students = $this->studentIdSearch($result['banner_id']);
} catch (\Intern\Exception\StudentNotFoundException $e) {
// Skip any students that are returned from the database, but don't exist
// in the student info web service
}
return $students;
}
示例13: pulse_install
/**
* @license http://opensource.org/licenses/lgpl-3.0.html
* @author Matthew McNaney <mcnaney at gmail dot com>
*/
function pulse_install(&$content)
{
$db = Database::newDB();
$db->begin();
try {
$pulse = new \pulse\PulseSchedule();
$st = $pulse->createTable($db);
} catch (\Exception $e) {
$error_query = $pulse->createQuery();
if (isset($st) && $db->tableExists($st->getName())) {
$st->drop();
}
$content[] = 'Query:' . $error_query;
$db->rollback();
throw $e;
}
$db->commit();
$content[] = 'Tables created';
return true;
}
示例14: loadSiteModules
protected function loadSiteModules()
{
$db = Database::newDB();
$mods = $db->addTable('modules');
$mods->addOrderBy($mods->getField('priority'));
$db->loadSelectStatement();
while ($row = $db->fetch()) {
$row = array_map('trim', $row);
if (is_file(PHPWS_SOURCE_DIR . 'mod/' . $row['title'] . '/Module.php')) {
$module = $this->loadModule($row);
} else {
$module = $this->loadCompatibilityModule($row);
}
$this->addModule($module);
}
if (count($this->getActiveModules()) == 0) {
// @todo better exceptions
throw new \Exception(t('No active modules installed'));
}
}
示例15: update_core_2_3_0
/**
*
* @author Matthew McNaney <mcnaney at gmail dot com>
* @package Global
* @license http://opensource.org/licenses/lgpl-3.0.html
*/
function update_core_2_3_0()
{
$db = Database::newDB();
$dtable = $db->addTable('modules');
if (!$dtable->columnExists('deprecated')) {
$deprecated = $dtable->addDataType('deprecated', 'smallint');
$deprecated->setDefault(1);
$deprecated->add();
}
$db2 = Database::newDB();
$db2->addTable('mod_settings');
$result = $db2->select();
if (!empty($result)) {
Settings::createSettingsTable();
$db3 = \Database::newDB();
$settings = $db3->addTable('settings');
$db3->delete();
foreach ($result as $v) {
$module = $setting_name = $setting_type = $small_num = $large_num = $small_char = $large_char = null;
extract($v);
$settings->addValue('module_name', $module);
$settings->addValue('variable_name', $setting_name);
switch ($setting_type) {
case 1:
$settings->addValue('setting', $small_num);
break;
case 2:
$settings->addValue('setting', $large_num);
break;
case 3:
$settings->addValue('setting', $small_char);
break;
case 4:
$settings->addValue('setting', $large_char);
break;
}
$settings->insert();
$settings->resetValues();
}
}
}