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


PHP Propel::getDB方法代码示例

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


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

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->c = new Criteria();
     $this->savedAdapter = Propel::getDB(null);
     Propel::setDB(null, new DBSQLite());
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:7,代码来源:CriteriaCombineTest.php

示例2: testInvalidCharset

 public function testInvalidCharset()
 {
     $this->markTestSkipped();
     $db = Propel::getDB(BookPeer::DATABASE_NAME);
     if ($db instanceof DBSQLite) {
         $this->markTestSkipped();
     }
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $a->save();
     $authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
     $a->setLastName($authorNameWindows1251);
     // Different databases seem to handle invalid data differently (no surprise, I guess...)
     if ($db instanceof DBPostgres) {
         try {
             $a->save();
             $this->fail("Expected an exception when saving non-UTF8 data to database.");
         } catch (Exception $x) {
             print $x;
         }
     } else {
         // No exception is thrown by MySQL ... (others need to be tested still)
         $a->save();
         $a->reload();
         $this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:28,代码来源:CharacterEncodingTest.php

示例3: addSortCriteria

 protected function addSortCriteria($c)
 {
     if ($sort_column = $this->getUser()->getAttribute('sort', 'nombre', 'sf_admin/cuenta/sort')) {
         $sort_column = Propel::getDB($c->getDbName())->quoteIdentifier($sort_column);
         if ($this->getUser()->getAttribute('type', 'asc', 'sf_admin/cuenta/sort') == 'asc') {
             $c->addAscendingOrderByColumn($sort_column);
         } else {
             $c->addDescendingOrderByColumn($sort_column);
         }
     }
 }
开发者ID:mediasadc,项目名称:alba,代码行数:11,代码来源:actions.class.php

示例4: testCreateSelectSqlPart

 public function testCreateSelectSqlPart()
 {
     Propel::setDb('oracle', new DBOracle());
     $db = Propel::getDB();
     $c = new Criteria();
     $c->addSelectColumn(BookPeer::ID);
     $c->addAsColumn('book_ID', BookPeer::ID);
     $fromClause = array();
     $selectSql = $db->createSelectSqlPart($c, $fromClause);
     $this->assertEquals('SELECT book.ID, book.ID AS book_ID', $selectSql, 'createSelectSqlPart() returns a SQL SELECT clause with both select and as columns');
     $this->assertEquals(array('book'), $fromClause, 'createSelectSqlPart() adds the tables from the select columns to the from clause');
 }
开发者ID:shelsonjava,项目名称:datawrapper,代码行数:12,代码来源:DBOracleTest.php

示例5: execute

 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->writeSection($output, '[Propel] You are running the command: propel:table:drop');
     $tablesToDelete = $input->getArgument('table');
     if ($input->getOption('force')) {
         $nbTable = count($tablesToDelete);
         $tablePlural = $nbTable > 1 || $nbTable == 0 ? 's' : '';
         if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
             $count = count($input->getArgument('table')) ?: 'all';
             $this->writeSection($output, 'WARNING: you are about to drop ' . $count . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
             if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
                 $output->writeln('<info>Aborted, nice decision !</info>');
                 return -2;
             }
         }
         try {
             list($name, $config) = $this->getConnection($input, $output);
             $connection = \Propel::getConnection($name);
             $adapter = \Propel::getDB($name);
             $showStatement = $connection->prepare('SHOW TABLES;');
             $showStatement->execute();
             $allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN);
             if ($nbTable) {
                 foreach ($tablesToDelete as $tableToDelete) {
                     if (!array_search($tableToDelete, $allTables)) {
                         throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete));
                     }
                 }
             } else {
                 $tablesToDelete = $allTables;
             }
             $connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
             array_walk($tablesToDelete, function (&$table, $key, $dbAdapter) {
                 $table = $dbAdapter->quoteIdentifierTable($table);
             }, $adapter);
             $tablesToDelete = join(', ', $tablesToDelete);
             if ('' !== $tablesToDelete) {
                 $connection->exec('DROP TABLE ' . $tablesToDelete . ' ;');
                 $output->writeln(sprintf('Table' . $tablePlural . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
             } else {
                 $output->writeln('<info>No tables have been dropped</info>');
             }
             $connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
         } catch (\Exception $e) {
             $this->writeSection($output, array('[Propel] Exception catched', '', $e->getMessage()), 'fg=white;bg=red');
         }
     } else {
         $output->writeln('<error>You have to use the "--force" option to drop some tables.</error>');
     }
 }
开发者ID:angelk,项目名称:PropelBundle,代码行数:55,代码来源:TableDropCommand.php

示例6: init

 /**
  * Init some properties with the help of outer class
  * @param      Criteria $criteria The outer class
  */
 public function init(Criteria $criteria)
 {
     // init $this->db
     try {
         $db = Propel::getDB($criteria->getDbName());
         $this->setDB($db);
     } catch (Exception $e) {
         // we are only doing this to allow easier debugging, so
         // no need to throw up the exception, just make note of it.
         Propel::log("Could not get a DBAdapter, sql may be wrong", Propel::LOG_ERR);
     }
     // init $this->realtable
     $realtable = $criteria->getTableForAlias($this->table);
     $this->realtable = $realtable ? $realtable : $this->table;
 }
开发者ID:nevalla,项目名称:Propel,代码行数:19,代码来源:Criterion.php

示例7: executeIndex

 public function executeIndex(sfWebRequest $request)
 {
     $this->setLayout(false);
     sfConfig::set('sf_web_debug', false);
     // Open the connection
     $con = \Propel::getConnection($request->getParameter('connection'));
     // Get the adapter
     $db = \Propel::getDB($request->getParameter('connection'));
     try {
         $this->query = base64_decode($request->getParameter('base64_query'));
         $stmt = $db->doExplainPlan($con, $this->query);
         $this->results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     } catch (Exception $e) {
         $this->getResponse()->setContent('<div class="error">This query cannot be explained.</div>');
     }
 }
开发者ID:nicolasmartinrojo,项目名称:sfPropelORMPlugin,代码行数:16,代码来源:actions.class.php

示例8: testMultipleFunctionInCriteria

 /**
  * @link       http://propel.phpdb.org/trac/ticket/425
  */
 public function testMultipleFunctionInCriteria()
 {
     $db = Propel::getDB(BookPeer::DATABASE_NAME);
     try {
         $c = new Criteria();
         $c->setDistinct();
         if ($db instanceof DBPostgres) {
             $c->addSelectColumn("substring(" . BookPeer::TITLE . " from position('Potter' in " . BookPeer::TITLE . ")) AS col");
         } else {
             $this->markTestSkipped();
         }
         $stmt = BookPeer::doSelectStmt($c);
     } catch (PropelException $x) {
         $this->fail("Paring of nested functions failed: " . $x->getMessage());
     }
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:19,代码来源:BasePeerTest.php

示例9: testGetLatestQuery

 public function testGetLatestQuery()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $con->setLastExecutedQuery(123);
     $this->assertEquals(123, $con->getLastExecutedQuery(), 'DebugPDO has getter and setter for last executed query');
     $c = new Criteria();
     $c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE);
     $books = BookPeer::doSelect($c, $con);
     $latestExecutedQuery = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.TITLE LIKE 'Harry%s'";
     if (!Propel::getDB(BookPeer::DATABASE_NAME)->useQuoteIdentifier()) {
         $latestExecutedQuery = str_replace('`', '', $latestExecutedQuery);
     }
     $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on every request');
     BookPeer::doDeleteAll($con);
     $latestExecutedQuery = "DELETE FROM book";
     $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on every request');
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:17,代码来源:DebugPDOTest.php

示例10: doBackupRecord

 public static function doBackupRecord(\Criteria $criteria, PropelPDO $con)
 {
     $db = Propel::getDB($criteria->getDbName());
     $dbMap = Propel::getDatabaseMap($criteria->getDbName());
     $keys = $criteria->keys();
     if (!empty($keys)) {
         $tableName = $criteria->getTableName($keys[0]);
     } else {
         throw new PropelException("Database insert attempted without anything specified to insert");
     }
     $tableMap = $dbMap->getTable($tableName);
     $whereClause = array();
     $peer = $tableMap->getPeerClassname();
     $versionTable = $peer::$workspaceBehaviorVersionName;
     $originTable = $tableMap->getName();
     $tables = $criteria->getTablesColumns();
     if (empty($tables)) {
         throw new \PropelException("Empty Criteria");
     }
     $fields = array_keys($tableMap->getColumns());
     $fields = implode(', ', $fields);
     foreach ($tables as $tableName => $columns) {
         $whereClause = array();
         $params = array();
         $stmt = null;
         try {
             foreach ($columns as $colName) {
                 $sb = "";
                 $criteria->getCriterion($colName)->appendPsTo($sb, $params);
                 $whereClause[] = $sb;
             }
             $sql = sprintf("INSERT INTO %s (%s) SELECT %s FROM %s WHERE %s", $versionTable, $fields, $fields, $originTable, implode(" AND ", $whereClause));
             $stmt = $con->prepare($sql);
             $db->bindValues($stmt, $params, $dbMap);
             $stmt->execute();
             $stmt->closeCursor();
         } catch (Exception $e) {
             Propel::log($e->getMessage(), Propel::LOG_ERR);
             throw new PropelException(sprintf('Unable to execute INSERT INTO statement [%s]', $sql), $e);
         }
     }
     // for each table
 }
开发者ID:marcj,项目名称:propel-workspace-behavior,代码行数:43,代码来源:WorkspaceBehaviorPeer.php

示例11: explainAction

 /**
  * Renders the profiler panel for the given token.
  *
  * @param string $token The profiler token
  * @param string $connection The connection name
  * @param integer $query
  *
  * @return Symfony\Component\HttpFoundation\Response A Response instance
  */
 public function explainAction($token, $connection, $query)
 {
     $profiler = $this->container->get('profiler');
     $profiler->disable();
     $profile = $profiler->loadProfile($token);
     $queries = $profile->getCollector('propel')->getQueries();
     if (!isset($queries[$query])) {
         return new Response('This query does not exist.');
     }
     // Open the connection
     $con = \Propel::getConnection($connection);
     // Get the adapter
     $db = \Propel::getDB($connection);
     try {
         $stmt = $db->doExplainPlan($con, $queries[$query]['sql']);
         $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     } catch (\Exception $e) {
         return new Response('<div class="error">This query cannot be explained.</div>');
     }
     return $this->container->get('templating')->renderResponse('PropelBundle:Panel:explain.html.twig', array('data' => $results, 'query' => $query));
 }
开发者ID:angelk,项目名称:PropelBundle,代码行数:30,代码来源:PanelController.php

示例12: testOrderByIgnoreCase

 public function testOrderByIgnoreCase()
 {
     $originalDB = Propel::getDB();
     Propel::setDB(null, new DBMySQL());
     $criteria = new Criteria();
     $criteria->setIgnoreCase(true);
     $criteria->addAscendingOrderByColumn(BookPeer::TITLE);
     $criteria->addAsColumn(BookPeer::TITLE, 'title');
     $params = array();
     $sql = BasePeer::createSelectSql($criteria, $params);
     $expectedSQL = 'SELECT UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC';
     $this->assertEquals($expectedSQL, $sql);
     $criteria = new Criteria();
     $criteria->setIgnoreCase(true);
     $criteria->addAscendingOrderByColumn(BookPeer::TITLE);
     BookPeer::addSelectColumns($criteria);
     $params = array();
     $sql = BasePeer::createSelectSql($criteria, $params);
     $expectedSQL = 'SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC';
     $this->assertEquals($expectedSQL, $sql);
     Propel::setDB(null, $originalDB);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:22,代码来源:CriteriaTest.php

示例13: populate

 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getDB()) != "DBOracle") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:mootools-forge,代码行数:101,代码来源:BookstoreDataPopulator.php

示例14: testDebugLatestQuery

 public function testDebugLatestQuery()
 {
     $con = Propel::getConnection(BookPeer::DATABASE_NAME);
     $c = new Criteria();
     $c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE);
     $con->useDebug(false);
     $this->assertEquals('', $con->getLastExecutedQuery(), 'PropelPDO reinitializes the latest query when debug is set to false');
     $books = BookPeer::doSelect($c, $con);
     $this->assertEquals('', $con->getLastExecutedQuery(), 'PropelPDO does not update the last executed query when useLogging is false');
     $con->useDebug(true);
     $books = BookPeer::doSelect($c, $con);
     $latestExecutedQuery = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.title LIKE 'Harry%s'";
     if (!Propel::getDB(BookPeer::DATABASE_NAME)->useQuoteIdentifier()) {
         $latestExecutedQuery = str_replace('`', '', $latestExecutedQuery);
     }
     $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query when useLogging is true');
     BookPeer::doDeleteAll($con);
     $latestExecutedQuery = "DELETE FROM `book`";
     $this->assertEquals($latestExecutedQuery, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on delete operations');
     $sql = 'DELETE FROM book WHERE 1=1';
     $con->exec($sql);
     $this->assertEquals($sql, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on exec operations');
     $sql = 'DELETE FROM book WHERE 2=2';
     $con->query($sql);
     $this->assertEquals($sql, $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on query operations');
     $stmt = $con->prepare('DELETE FROM book WHERE 1=:p1');
     $stmt->bindValue(':p1', '2');
     $stmt->execute();
     $this->assertEquals("DELETE FROM book WHERE 1='2'", $con->getLastExecutedQuery(), 'PropelPDO updates the last executed query on prapared statements');
     $con->useDebug(false);
     $this->assertEquals('', $con->getLastExecutedQuery(), 'PropelPDO reinitializes the latest query when debug is set to false');
     $con->useDebug(true);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:33,代码来源:PropelPDOTest.php

示例15: getCountStatement

 protected function getCountStatement($con = null)
 {
     $dbMap = Propel::getDatabaseMap($this->getDbName());
     $db = Propel::getDB($this->getDbName());
     if ($con === null) {
         $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
     }
     // check that the columns of the main class are already added (if this is the primary ModelCriteria)
     if (!$this->hasSelectClause() && !$this->getPrimaryCriteria()) {
         $this->addSelfSelectColumns();
     }
     $this->configureSelectColumns();
     $needsComplexCount = $this->getGroupByColumns() || $this->getOffset() || $this->getLimit() || $this->getHaving() || in_array(Criteria::DISTINCT, $this->getSelectModifiers());
     try {
         $this->basePreSelect($con);
         $params = array();
         if ($needsComplexCount) {
             if (BasePeer::needsSelectAliases($this)) {
                 if ($this->getHaving()) {
                     throw new PropelException('Propel cannot create a COUNT query when using HAVING and  duplicate column names in the SELECT part');
                 }
                 $db->turnSelectColumnsToAliases($this);
             }
             $selectSql = BasePeer::createSelectSql($this, $params);
             $sql = 'SELECT COUNT(*) FROM (' . $selectSql . ') propelmatch4cnt';
         } else {
             // Replace SELECT columns with COUNT(*)
             $this->clearSelectColumns()->addSelectColumn('COUNT(*)');
             $sql = BasePeer::createSelectSql($this, $params);
         }
         $stmt = $con->prepare($sql);
         $db->bindValues($stmt, $params, $dbMap);
         $stmt->execute();
     } catch (PropelException $e) {
         if ($stmt) {
             $stmt = null;
             // close
         }
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute COUNT statement [%s]', $sql), $e);
     }
     return $stmt;
 }
开发者ID:halfer,项目名称:Meshing,代码行数:43,代码来源:ModelCriteria.php


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