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


PHP Context::getConnection方法代码示例

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


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

示例1: getDBInfo

 /** Funkcia v poli vrati zakladne info. o pripojeni.
  * @return array
  */
 public function getDBInfo()
 {
     $pom = explode(":", $this->connection->getConnection()->getDsn());
     $out = array();
     foreach (explode(";", $pom[1]) as $v) {
         $t = explode("=", $v);
         $out[$t[0]] = $t[1];
     }
     return $out;
 }
开发者ID:petak23,项目名称:scspp,代码行数:13,代码来源:Table.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = $this->database->getConnection();
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USERS_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_ROLES_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_RESOURCES_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USER_ROLE_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USER_REQUEST_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_ROLES_DATA_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_IDENTITY_HASH_TABLE));
 }
开发者ID:trejjam,项目名称:authorization,代码行数:11,代码来源:Install.php

示例3: loadFile

 /**
  * Import taken from Adminer, slightly modified
  *
  * @param    string path to imported file
  * @param    DibiConnection
  * @returns  int number of executed queries
  *
  * @author   Jakub Vrána
  * @author   Jan Tvrdík
  * @author   Michael Moravec
  * @author   Jan Skrasek
  * @license  Apache License
  */
 protected function loadFile($file)
 {
     $query = @file_get_contents($file);
     if (!$query) {
         throw new IOException("Cannot open file '{$file}'.");
     }
     $delimiter = ';';
     $offset = $queries = 0;
     $space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\\n]*\\n|--\\n)";
     $driver = $this->context->getConnection()->getSupplementalDriver();
     if ($driver instanceof MsSqlDriver) {
         $parse = '[\'"[]|/\\*|-- |$';
     } elseif ($driver instanceof SqliteDriver) {
         $parse = '[\'"`[]|/\\*|-- |$';
     } elseif ($driver instanceof PgSqlDriver) {
         $parse = '[\'"]|/\\*|-- |$|\\$[^$]*\\$';
     } else {
         $parse = '[\'"`#]|/\\*|-- |$';
     }
     while ($query != '') {
         if (!$offset && preg_match("~^{$space}*DELIMITER\\s+(\\S+)~i", $query, $match)) {
             $delimiter = $match[1];
             $query = substr($query, strlen($match[0]));
         } else {
             preg_match('(' . preg_quote($delimiter) . "\\s*|{$parse})", $query, $match, PREG_OFFSET_CAPTURE, $offset);
             // should always match
             $found = $match[0][0];
             $offset = $match[0][1] + strlen($found);
             if (!$found && rtrim($query) === '') {
                 break;
             }
             if (!$found || rtrim($found) == $delimiter) {
                 // end of a query
                 $q = substr($query, 0, $match[0][1]);
                 $queries++;
                 $this->context->query($q);
                 $query = substr($query, $offset);
                 $offset = 0;
             } else {
                 // find matching quote or comment end
                 while (preg_match('(' . ($found == '/*' ? '\\*/' : ($found == '[' ? ']' : (preg_match('~^-- |^#~', $found) ? "\n" : preg_quote($found) . "|\\\\."))) . '|$)s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
                     //! respect sql_mode NO_BACKSLASH_ESCAPES
                     $s = $match[0][0];
                     $offset = $match[0][1] + strlen($s);
                     if ($s[0] !== '\\') {
                         break;
                     }
                 }
             }
         }
     }
     return $queries;
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:66,代码来源:NetteDbSql.php

示例4: processViews

 private function processViews()
 {
     $tables = $this->db->getConnection()->getSupplementalDriver()->getTables();
     foreach ($tables as $table) {
         if ($table['view'] == TRUE) {
             $viewName = $table['name'];
             // Fetch SHOW CREATE VIEW string
             $row = $this->db->query("SHOW CREATE VIEW `{$viewName}`")->fetch();
             $createView = $row["Create View"];
             // Remove Auto increment value
             $createView = Strings::replace($createView, '#SQL SECURITY DEFINER\\s?#i');
             $createView = Strings::replace($createView, '#ALGORITHM=UNDEFINED\\s?#i');
             $createView = Strings::replace($createView, '/DEFINER=`.+?`\\@`.+?`\\s?/');
             // Add ;
             $createView .= ";";
             $dropTable = "DROP VIEW IF EXISTS `{$viewName}`;\n";
             $data = Data::header() . $dropTable . $createView . "\n" . Data::footer();
             $dump = new Dump($viewName, Dump::TYPE_VIEW, $this->dumpDir);
             $dump->saveIfChanged($data, function ($fromFile) use($createView) {
                 $createViewFromFile = Strings::match($fromFile, "/CREATE.*;/s")[0];
                 return Strings::normalize($createViewFromFile) == Strings::normalize($createView);
             });
         }
     }
 }
开发者ID:filsedla,项目名称:dbtool,代码行数:25,代码来源:DbTool.php

示例5: __construct

 public function __construct($tableName, Context $context)
 {
     $this->tableName = $tableName;
     $this->driver = $context->getConnection()->getSupplementalDriver();
     $this->conventions = $context->getConventions();
     $this->structure = $context->getStructure();
     $this->delimitedTable = implode('.', array_map([$this->driver, 'delimite'], explode('.', $tableName)));
 }
开发者ID:ricco24,项目名称:database,代码行数:8,代码来源:SqlBuilder.php

示例6: selectionBy

 /**
  * Helper for findBy, countBy
  *
  * @param array   $values
  * @param array   $order Order => column=>ASC/DESC
  * @param integer $limit Limit count
  * @param integer $offset Limit offset
  *
  * @return Nette\Database\Table\Selection
  */
 protected function selectionBy(array $values, $order = null, $limit = null, $offset = null)
 {
     $selection = $this->getTable();
     // compose Where
     foreach ($values as $key => $value) {
         // translate property name to SQL column name
         $keyTranslate = $this->translatePropertyToColumnSQL($key);
         if (is_int($key) and is_array($value)) {
             // multiple parameters in array must be first condition like (col = ? OR col = ? OR col2 = ?) and next is parameters
             $value[0] = $this->translatePropertyToColumnSQL($value[0]);
             call_user_func_array([$selection, "where"], $value);
         } else {
             $selection->where($keyTranslate, $value);
         }
     }
     // compose permanently filter
     foreach ($this->getPermanentlyFilter() as $key => $value) {
         // translate property name to SQL column name
         $keyTranslate = $this->translatePropertyToColumnSQL($key);
         if (is_int($key) and is_array($value)) {
             // multiple parameters in array must be first condition like (col = ? OR col = ? OR col2 = ?) and next is parameters
             $value[0] = $this->translatePropertyToColumnSQL($value[0]);
             call_user_func_array([$selection, "where"], $value);
         } else {
             $selection->where($keyTranslate, $value);
         }
     }
     // compose Order
     if ($order !== null) {
         $orderString = "";
         foreach ($order as $column => $ascdesc) {
             // translate properties to SQL column name
             $columnTranslate = $this->translatePropertyToColumnSQL($column);
             $orderString .= ($orderString ? "," : "") . $columnTranslate . (strtolower($ascdesc) == "desc" ? " DESC" : "");
         }
         if ($orderString) {
             $selection->order($orderString);
         } else {
         }
     }
     // compose Limit
     if ($limit !== null) {
         if ($offset !== null) {
             $selection->limit((int) $limit, (int) $offset);
         } else {
             $selection->limit((int) $limit);
         }
     }
     if ($limit !== null and !$order) {
         // is MS SQL? need order for OFFSET
         if ($this->database->getConnection()->getSupplementalDriver() instanceof Nette\Database\Drivers\SqlsrvDriver) {
             $selection->order($selection->getPrimary());
         }
     }
     return $selection;
 }
开发者ID:mepatek,项目名称:application,代码行数:66,代码来源:AbstractNetteDatabaseMapper.php

示例7: __construct

 public function __construct(Nette\Database\Context $context)
 {
     trigger_error(sprintf('Class %s is deprecated, use class SqlHandler instead.', __CLASS__), E_USER_DEPRECATED);
     $connection = $context->getConnection();
     $driver = $connection->getSupplementalDriver();
     $dbal = new NetteAdapter($connection);
     if ($driver instanceof Nette\Database\Drivers\PgSqlDriver) {
         parent::__construct(new PgSqlDriver($dbal, 'migrations'));
     } elseif ($driver instanceof Nette\Database\Drivers\MySqlDriver) {
         parent::__construct(new MySqlDriver($dbal, 'migrations'));
     } else {
         throw new \LogicException();
     }
 }
开发者ID:artfocus,项目名称:migrations,代码行数:14,代码来源:NetteDbSql.php

示例8: insert

 /**
  * Inserts row in a table.
  * @param  array|\Traversable|Selection array($column => $value)|\Traversable|Selection for INSERT ... SELECT
  * @return IRow|int|bool Returns IRow or number of affected rows for Selection or table without primary key
  */
 public function insert($data)
 {
     if ($data instanceof self) {
         $return = $this->context->queryArgs($this->sqlBuilder->buildInsertQuery() . ' ' . $data->getSql(), $data->getSqlBuilder()->getParameters());
     } else {
         if ($data instanceof \Traversable) {
             $data = iterator_to_array($data);
         }
         $return = $this->context->query($this->sqlBuilder->buildInsertQuery() . ' ?values', $data);
     }
     $this->loadRefCache();
     if ($data instanceof self || $this->primary === NULL) {
         unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]);
         return $return->getRowCount();
     }
     $primarySequenceName = $this->getPrimarySequence();
     $primaryKey = $this->context->getInsertId(!empty($primarySequenceName) ? $this->context->getConnection()->getSupplementalDriver()->delimite($primarySequenceName) : $primarySequenceName);
     if ($primaryKey === FALSE) {
         unset($this->refCache['referencing'][$this->getGeneralCacheKey()][$this->getSpecificCacheKey()]);
         return $return->getRowCount();
     }
     if (is_array($this->getPrimary())) {
         $primaryKey = array();
         foreach ((array) $this->getPrimary() as $key) {
             if (!isset($data[$key])) {
                 return $data;
             }
             $primaryKey[$key] = $data[$key];
         }
         if (count($primaryKey) === 1) {
             $primaryKey = reset($primaryKey);
         }
     }
     $row = $this->createSelectionInstance()->select('*')->wherePrimary($primaryKey)->fetch();
     if ($this->rows !== NULL) {
         if ($signature = $row->getSignature(FALSE)) {
             $this->rows[$signature] = $row;
             $this->data[$signature] = $row;
         } else {
             $this->rows[] = $row;
             $this->data[] = $row;
         }
     }
     return $row;
 }
开发者ID:jave007,项目名称:test,代码行数:50,代码来源:Selection.php

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = $this->database->getConnection();
     $driverName = $connection->getPdo()->getAttribute(\PDO::ATTR_DRIVER_NAME);
     Nette\Database\Helpers::loadFromFile($connection, $this->getFileName($driverName . '.' . static::FILE_LABELS_TABLE));
 }
开发者ID:trejjam,项目名称:utils,代码行数:6,代码来源:Install.php

示例10: __construct

 /** @param  NdbContext $database */
 public function __construct(NdbContext $database)
 {
     $this->database = $database;
     $this->transaction = new Transaction($database->getConnection());
 }
开发者ID:uestla,项目名称:yetorm,代码行数:6,代码来源:Repository.php

示例11: getPdo

 public function getPdo()
 {
     return $this->context->getConnection()->getPdo();
 }
开发者ID:HotelQuickly,项目名称:NettePhpunit,代码行数:4,代码来源:NetteConnection.php

示例12: __construct

 public function __construct(Nette\Database\Context $context, $tableName)
 {
     trigger_error(sprintf('Class %s is deprecated, use class MySqlDriver instead.', __CLASS__), E_USER_DEPRECATED);
     parent::__construct(new NetteAdapter($context->getConnection()), $tableName);
 }
开发者ID:artfocus,项目名称:migrations,代码行数:5,代码来源:MySqlNetteDbDriver.php

示例13: __construct

 public function __construct(Context $context, $tableName)
 {
     $this->context = $context;
     $this->delimitedTableName = $context->getConnection()->getSupplementalDriver()->delimite($tableName);
     $this->delimitedLockTableName = $context->getConnection()->getSupplementalDriver()->delimite($tableName . '_lock');
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:6,代码来源:NetteDbDriver.php

示例14: renderFilter

 public function renderFilter($categoryId = null, $manufacturerId = null)
 {
     $this->template->goodsRecommended = array();
     $this->template->goodsOther = array();
     $this->template->selectedCategoryId = $categoryId;
     $this->template->selectedSubcategoryId = $categoryId;
     $this->template->selectedManufacturerId = $manufacturerId;
     if ($categoryId && $manufacturerId) {
         $category = $this->category->createSelectionInstance()->get($categoryId);
         $manufacturer = $this->manufacturer->get($manufacturerId);
         if (!$category || !$manufacturer) {
             $this->flashMessage('Kategorie nebo výrobce nebyl nalezen.', 'warning');
         } else {
             $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null;
             $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name . " od " . $manufacturer->name;
             $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)];
             $in = $category . ',';
             $subcategories = $category->related('category.parent');
             foreach ($subcategories as $subcategory) {
                 $in .= $subcategory . ',';
             }
             $in = rtrim($in, ',');
             $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.`manufacturer_id` = {$manufacturerId} AND g.recommended = ";
             $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs());
             $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs());
             if ($category->parent) {
                 $this->template->selectedCategoryId = $category->parent;
                 $this->template->selectedSubCategoryId = $categoryId;
             } else {
                 $this->template->selectedCategoryId = $categoryId;
             }
         }
     } elseif ($categoryId) {
         $category = $this->category->createSelectionInstance()->get($categoryId);
         if (!$category) {
             $this->flashMessage('Kategorie nebyla nalezena.', 'warning');
         } else {
             $parentCategory = $category->parent ? $this->category->createSelectionInstance()->get($category->parent) : null;
             $this->template->filterName = ($parentCategory ? $parentCategory->name . ' - ' : '') . $category->name;
             $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($category->description)];
             $in = $category . ',';
             $subcategories = $category->related('category.parent');
             foreach ($subcategories as $subcategory) {
                 $in .= $subcategory . ',';
             }
             $in = rtrim($in, ',');
             $sql = "SELECT g.id\n\t\t\t\t\t\tFROM category_goods cg\n\t\t\t\t\t\tJOIN goods g ON cg.`goods_id` = g.id\n\t\t\t\t\t\tJOIN category c ON cg.`category_id` = c.id\n\t\t\t\t\t\tWHERE cg.`category_id` IN ({$in}) AND g.recommended = ";
             $this->template->goodsRecommended = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "1 GROUP BY id")->fetchPairs());
             $this->template->goodsOther = $this->good->createSelectionInstance()->where('id', $this->database->getConnection()->query($sql . "0 GROUP BY id")->fetchPairs());
             if ($category->parent) {
                 $this->template->selectedCategoryId = $category->parent;
                 $this->template->selectedSubCategoryId = $categoryId;
             } else {
                 $this->template->selectedCategoryId = $categoryId;
             }
         }
     } elseif ($manufacturerId) {
         $manufacturer = $this->manufacturer->get($manufacturerId);
         if (!$manufacturer) {
             $this->flashMessage('Výrobce nebyl nalezen.', 'warning');
         } else {
             $this->template->filterName = $manufacturer->name;
             $this->template->goodsRecommended = $this->good->where('manufacturer_id = ? AND recommended != 0', $manufacturerId)->order('id DESC');
             $this->template->goodsOther = $this->good->createSelectionInstance()->where('manufacturer_id = ? AND recommended = 0', $manufacturerId)->order('id DESC');
             $this->template->selectedManufacturer = $manufacturerId;
             $this->template->og = ['title' => $this->template->filterName . ' - alena.cz', 'description' => strip_tags($manufacturer->description)];
         }
     } else {
         $this->redirect("default");
     }
 }
开发者ID:vladimirslevercz,项目名称:alena,代码行数:71,代码来源:CatalogPresenter.php

示例15: __construct

 public function __construct($table, Nette\Database\Context $context)
 {
     parent::__construct($context->getConnection(), $table, $context->getDatabaseReflection());
 }
开发者ID:dansilovsky,项目名称:calendar,代码行数:4,代码来源:Repository.php


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