当前位置: 首页>>代码示例>>PHP>>正文


PHP Database::connection方法代码示例

本文整理汇总了PHP中Database::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::connection方法的具体用法?PHP Database::connection怎么用?PHP Database::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


在下文中一共展示了Database::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build

 public function build($runData)
 {
     // just get some numbers
     $db = Database::connection();
     $q = "SELECT count(*) AS c FROM ozone_user";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalUsers = $row['c'];
     /* -2 because there are 2 "ghost users" in the default installation 
     			with user_id < 0 */
     $runData->contextAdd("totalUsers", $totalUsers - 2);
     $q = "SELECT count(*) AS c FROM site";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalSites = $row['c'];
     $runData->contextAdd("totalSites", $totalSites);
     $q = "SELECT count(*) AS c FROM page";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalPages = $row['c'];
     $runData->contextAdd("totalPages", $totalPages);
     $q = "SELECT count(*) AS c FROM ozone_user WHERE registered_date>now() - interval '1 day'";
     $res = $db->query($q);
     $row = $res->nextRow();
     $newUsers = $row['c'];
     $runData->contextAdd("newUsers", $newUsers);
     $q = "SELECT count(*) AS c FROM page_revision WHERE date_last_edited>now() - interval '1 day'";
     $res = $db->query($q);
     $row = $res->nextRow();
     $recentEdits = $row['c'];
     $runData->contextAdd("recentEdits", $recentEdits);
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:32,代码来源:SomeGlobalStatsModule.php

示例2: process

 public function process($data)
 {
     // does not use data
     $search = $_GET['q'];
     if ($search == null || strlen($search) == 0) {
         return;
     }
     $search1 = pg_escape_string(preg_quote($search));
     $search2 = pg_escape_string($search);
     Database::init();
     $q1 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name ~* '^{$search1}' AND nick_name != '{$search2}'";
     $q1 .= "ORDER BY nick_name LIMIT 20";
     $q2 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name = '{$search2}' ";
     $db = Database::connection();
     $result1 = $db->query($q1);
     $result1 = $result1->fetchAll();
     $result2 = $db->query($q2);
     $result2 = $result2->fetchAll();
     if ($result1 == null && $result2 != null) {
         $result = $result2;
     }
     if ($result2 == null && $result1 != null) {
         $result = $result1;
     }
     if ($result1 == null && $result2 == null) {
         $result = false;
     }
     // NOT null since it breakes autocomplete!!!
     if ($result1 != null && $result2 != null) {
         $result = array_merge($result2, $result1);
     }
     return array('users' => $result);
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:33,代码来源:UserLookupQModule.php

示例3: build

 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get
     $q = "SELECT target_user_id, count(*) AS rank " . "FROM user_abuse_flag " . "WHERE site_id='" . $site->getSiteId() . "' " . "AND site_valid = TRUE GROUP BY target_user_id ORDER BY rank DESC, target_user_id";
     $db = Database::connection();
     $res = $db->query($q);
     $all = $res->fetchAll();
     $r2 = array();
     if ($all) {
         foreach ($all as &$r) {
             // get user
             $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($r['target_user_id']);
             if ($user) {
                 $r['user'] = $user;
                 // check if member
                 $c = new Criteria();
                 $c->add("site_id", $site->getSiteId());
                 $c->add("user_id", $user->getUserId());
                 $mem = DB_MemberPeer::instance()->selectOne($c);
                 if ($mem) {
                     $r['member'] = $mem;
                 }
                 $r2[] = $r;
             }
         }
     }
     $runData->contextAdd("reps", $r2);
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:29,代码来源:ManageSiteUserAbuseModule.php

示例4: import

 public function import(\SimpleXMLElement $sx)
 {
     $em = \Database::connection()->getEntityManager();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Entity')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     if (isset($sx->expressentities)) {
         foreach ($sx->expressentities->entity as $entityNode) {
             $entity = $em->find('Concrete\\Core\\Entity\\Express\\Entity', (string) $entityNode['id']);
             if (!is_object($entity)) {
                 $entity = new Entity();
                 $entity->setId((string) $entityNode['id']);
             }
             $entity->setPluralHandle((string) $entityNode['plural_handle']);
             $entity->setHandle((string) $entityNode['handle']);
             $entity->setDescription((string) $entityNode['description']);
             $entity->setName((string) $entityNode['name']);
             if ((string) $entityNode['include_in_public_list'] == '') {
                 $entity->setIncludeInPublicList(false);
             }
             $entity->setHandle((string) $entityNode['handle']);
             $tree = ExpressEntryResults::get();
             $node = $tree->getNodeByDisplayPath((string) $entityNode['results-folder']);
             $node = \Concrete\Core\Tree\Node\Type\ExpressEntryResults::add((string) $entityNode['name'], $node);
             $entity->setEntityResultsNodeId($node->getTreeNodeID());
             $indexer = $entity->getAttributeKeyCategory()->getSearchIndexer();
             if (is_object($indexer)) {
                 $indexer->createRepository($entity->getAttributeKeyCategory());
             }
             $em->persist($entity);
         }
     }
     $em->flush();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Entity')->setIdGenerator(new UuidGenerator());
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:33,代码来源:ImportExpressEntitiesRoutine.php

示例5: getConnection

 private static function getConnection()
 {
     if (self::$connection == null) {
         self::$connection = mysqli_connect("localhost", "root", "", "postthelink_base");
     }
     return self::$connection;
 }
开发者ID:mega8bit,项目名称:PostTheLink,代码行数:7,代码来源:index.php

示例6: CreateConnection

 private static function CreateConnection()
 {
     self::$connection = new \PDO('mysql:host=' . self::$dsn . ';dbname=' . self::$database . ';', self::$username, self::$password, array(\PDO::FETCH_OBJ));
     self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     self::$connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
     return self::$connection;
 }
开发者ID:ehamrin,项目名称:cmsPlugin,代码行数:7,代码来源:Database.php

示例7: run

 public function run()
 {
     // check!
     $c = new Criteria();
     $c->add("status", null);
     $c->addOrderDescending("backup_id");
     $sb = DB_SiteBackupPeer::instance()->selectOne($c);
     // select only one!
     if (!$sb) {
         return;
     }
     $db = Database::connection();
     $sb->setStatus("started");
     $sb->save();
     $db->begin();
     try {
         $b = new Backuper();
         $b->setConfig($sb);
         $b->backup();
         // check
         $sb->setStatus("completed");
         $sb->setDate(new ODate());
         $sb->setRand($b->getRand());
         $sb->save();
     } catch (Exception $e) {
         $sb->setStatus("failed");
         $sb->save();
     }
     $db->commit();
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:30,代码来源:HandleBackupRequestsJob.php

示例8: connect

 public static function connect()
 {
     if (!isset(self::$connection)) {
         self::$connection = new Database();
     }
     return self::$pdo;
 }
开发者ID:doroshchenko,项目名称:dynamic_forms,代码行数:7,代码来源:Database.php

示例9: getInstance

 public static function getInstance()
 {
     if (is_null(self::$connection)) {
         self::$connection = new Database();
     }
     return self::$connection;
 }
开发者ID:ThinkersForLife,项目名称:shellpage,代码行数:7,代码来源:database_class_before_cisco.php

示例10: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = \Database::connection();
     $em = $db->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
     $cacheDriver->flushAll();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemas = [];
     /**
      * @var $sm MySqlSchemaManager
      */
     $sm = $db->getSchemaManager();
     $dbSchema = $sm->createSchema();
     // core xml tables
     $schemas[] = Schema::getCoreXMLSchema();
     // core entities
     $sm = new DatabaseStructureManager($em);
     $entities = $sm->getMetadatas();
     $schemas[] = $tool->getSchemaFromMetadata($entities);
     // core, application and package block types
     $env = Environment::get();
     $list = new BlockTypeList();
     $list->includeInternalBlockTypes();
     foreach ($list->get() as $bt) {
         $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
         if ($r->exists()) {
             $parser = Schema::getSchemaParser(simplexml_load_file($r->file));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // packages
     $packages = Package::getInstalledList();
     foreach ($packages as $pkg) {
         $xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
         if (file_exists($xmlFile)) {
             $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // Finalize output.
     $comparator = new \Doctrine\DBAL\Schema\Comparator();
     $saveQueries = array();
     foreach ($schemas as $schema) {
         $schemaDiff = $comparator->compare($dbSchema, $schema);
         $saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
     }
     $saveQueries = $this->filterQueries($saveQueries);
     if (count($saveQueries)) {
         $output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
         $i = 1;
         foreach ($saveQueries as $query) {
             $output->writeln(sprintf('%s: %s', $i, $query));
             $i++;
         }
     } else {
         $output->writeln(t('No differences found between schema and database.'));
     }
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:60,代码来源:CompareSchemaCommand.php

示例11: getDatabase

 /**
  * @return DatabaseConnection
  * @desc Gets the one and only global database connection
  */
 public static function getDatabase()
 {
     if (empty(self::$connection)) {
         self::$connection = new DatabaseConnection();
     }
     return self::$connection;
 }
开发者ID:pilif,项目名称:phexrep,代码行数:11,代码来源:database.php

示例12: popular

 public static function popular()
 {
     $pdo = Database::connection();
     $sql = 'SELECT * FROM produtos ORDER BY quantidadeDeAcessos DESC LIMIT 5';
     $query = $pdo->query($sql);
     return $query->fetchAll(PDO::FETCH_ASSOC);
 }
开发者ID:jacksongomesbr,项目名称:livro-web-codigo-fonte,代码行数:7,代码来源:Produtos.php

示例13: build

 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $db = Database::connection();
     $db->begin();
     $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId);
     if ($thread == null || $thread->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("No thread found... Is it deleted?"), "no_thread");
     }
     // check if thread blocked
     if ($thread->getBlocked()) {
         // check if moderator or admin
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("user_id", $user->getUserId());
         $rel = DB_ModeratorPeer::instance()->selectOne($c);
         if (!$rel || strpos($rel->getPermissions(), 'f') == false) {
             $rel = DB_AdminPeer::instance()->selectOne($c);
             if (!$rel) {
                 throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can add new posts nor edit existing ones."));
             }
         }
     }
     $category = $thread->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_thread', $runData->getUser(), $category, $thread);
     $runData->contextAdd("thread", $thread);
     $db->commit();
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:31,代码来源:ForumEditThreadMetaModule.php

示例14: connectify

 /**
  * Main db Connection
  */
 public static function connectify()
 {
     if (Database::$connection == null) {
         Database::$connection = new PDO(Database::$driver . ';' . 'Server=' . Database::$host . ';' . 'Database=' . Database::$db . ';', Database::$user, Database::$pass);
     }
     return Database::$connection;
 }
开发者ID:vincentnacar02,项目名称:beans-php,代码行数:10,代码来源:Database.php

示例15: initialize

 /**
  * Initializes this database class.
  */
 private static function initialize()
 {
     if (self::$connection != null) {
         return;
     }
     self::$connection = self::getConnection();
 }
开发者ID:brandonfrancis,项目名称:scsapi,代码行数:10,代码来源:database.php


注:本文中的Database::connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。