本文整理汇总了PHP中Cake\Datasource\ConnectionManager::config方法的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager::config方法的具体用法?PHP ConnectionManager::config怎么用?PHP ConnectionManager::config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Datasource\ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWrongCredentials
/**
* Tests that connecting with invalid credentials or database name throws an exception
*
* @expectedException \Cake\Database\Exception\MissingConnectionException
* @return void
*/
public function testWrongCredentials()
{
$config = ConnectionManager::config('test');
$this->skipIf(isset($config['url']), 'Datasource has dsn, skipping.');
$connection = new Connection(['database' => '/dev/nonexistent'] + ConnectionManager::config('test'));
$connection->connect();
}
示例2: setUpBeforeClass
/**
* Set up some fake datasources and security salt **once** before all tests.
*
* @return void
* @see ::testMainSpecialKeys()
*/
public static function setUpBeforeClass()
{
// Prime the ConnectionManager with some configs.
\Cake\Datasource\ConnectionManager::config(self::$datasources);
// Prime the security salt.
\Cake\Utility\Security::salt(self::$salt);
}
示例3: getConfig
/**
* Overrides the original method from phinx in order to return a tailored
* Config object containing the connection details for the database.
*
* @return Phinx\Config\Config
*/
public function getConfig()
{
if ($this->configuration) {
return $this->configuration;
}
$folder = 'Migrations';
if ($this->input->getOption('source')) {
$folder = $this->input->getOption('source');
}
$dir = ROOT . DS . 'config' . DS . $folder;
$plugin = null;
if ($this->input->getOption('plugin')) {
$plugin = $this->input->getOption('plugin');
$dir = Plugin::path($plugin) . 'config' . DS . $folder;
}
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$plugin = $plugin ? Inflector::underscore($plugin) . '_' : '';
$plugin = str_replace(array('\\', '/', '.'), '_', $plugin);
$connection = 'default';
if ($this->input->getOption('connection')) {
$connection = $this->input->getOption('connection');
}
$config = ConnectionManager::config($connection);
return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $this->getAdapterName($config['driver']), 'host' => isset($config['host']) ? $config['host'] : null, 'user' => isset($config['username']) ? $config['username'] : null, 'pass' => isset($config['password']) ? $config['password'] : null, 'port' => isset($config['port']) ? $config['port'] : null, 'name' => $config['database'], 'charset' => $config['encoding']]]]);
}
示例4: getConfig
/**
* Overrides the original method from phinx in order to return a tailored
* Config object containing the connection details for the database.
*
* @param bool $forceRefresh
* @return \Phinx\Config\Config
*/
public function getConfig($forceRefresh = false)
{
if ($this->configuration && $forceRefresh === false) {
return $this->configuration;
}
$folder = 'Migrations';
if ($this->input->getOption('source')) {
$folder = $this->input->getOption('source');
}
$dir = ROOT . DS . 'config' . DS . $folder;
$plugin = null;
if ($this->input->getOption('plugin')) {
$plugin = $this->input->getOption('plugin');
$dir = Plugin::path($plugin) . 'config' . DS . $folder;
}
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$plugin = $plugin ? Inflector::underscore($plugin) . '_' : '';
$plugin = str_replace(['\\', '/', '.'], '_', $plugin);
$connection = $this->getConnectionName($this->input);
$connectionConfig = ConnectionManager::config($connection);
$adapterName = $this->getAdapterName($connectionConfig['driver']);
$config = ['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]];
if ($adapterName === 'mysql') {
if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) {
$config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key'];
$config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert'];
}
if (!empty($connectionConfig['ssl_ca'])) {
$config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca'];
}
}
return $this->configuration = new Config($config);
}
示例5: getConfig
/**
* Overrides the original method from phinx in order to return a tailored
* Config object containing the connection details for the database.
*
* @param bool $forceRefresh
* @return \Phinx\Config\Config
*/
public function getConfig($forceRefresh = false)
{
if ($this->configuration && $forceRefresh === false) {
return $this->configuration;
}
$migrationsPath = $this->getOperationsPath($this->input);
$seedsPath = $this->getOperationsPath($this->input, 'Seeds');
$plugin = $this->getPlugin($this->input);
if (!is_dir($migrationsPath)) {
mkdir($migrationsPath, 0777, true);
}
if (!is_dir($seedsPath)) {
mkdir($seedsPath, 0777, true);
}
$phinxTable = $this->getPhinxTable($plugin);
$connection = $this->getConnectionName($this->input);
$connectionConfig = ConnectionManager::config($connection);
$adapterName = $this->getAdapterName($connectionConfig['driver']);
$config = ['paths' => ['migrations' => $migrationsPath, 'seeds' => $seedsPath], 'environments' => ['default_migration_table' => $phinxTable, 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]];
if ($adapterName === 'pgsql') {
if (!empty($connectionConfig['schema'])) {
$config['environments']['default']['schema'] = $connectionConfig['schema'];
}
}
if ($adapterName === 'mysql') {
if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) {
$config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key'];
$config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert'];
}
if (!empty($connectionConfig['ssl_ca'])) {
$config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca'];
}
}
return $this->configuration = new Config($config);
}
示例6: testWithPreMadeConnection
public function testWithPreMadeConnection()
{
ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite']);
$module = new CakeDbModule('default');
$instance = (new Injector($module, $_ENV['TMP_DIR']))->getInstance('Cake\\Database\\Connection');
$this->assertSame(ConnectionManager::get('default'), $instance);
}
示例7: __construct
public function __construct()
{
$config = ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'database' => Configure::get('database.database'), 'username' => Configure::get('database.username'), 'password' => Configure::get('database.password'), 'host' => Configure::get('database.host'), 'persistent' => Configure::get('database.persistant'), 'encoding' => Configure::get('database.encoding'), 'timezone' => Configure::get('database.timezone'), 'quoteIdentifiers' => Configure::get('database.quoteIdentifiers'), 'log' => Configure::get('database.log')];
ConnectionManager::config('default', $config);
$link = ConnectionManager::get('default');
self::$_logger = new QueryLogger();
$link->logger(self::$_logger);
}
示例8: setUp
protected function setUp()
{
parent::setUp();
$configured = ConnectionManager::configured();
if (empty($configured)) {
ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => self::SQLITE_PATH]);
}
$this->Posts = TableRegistry::get('Posts');
}
示例9: getMaxNo
public function getMaxNo($restaurantId)
{
$datasource = ConnectionManager::config('default');
$connection = mysql_connect($datasource['host'], $datasource['username'], $datasource['password']);
mysql_select_db($datasource['database'], $connection);
$query = "call RestaurantDB.getMaxTakeawayNo(" . $restaurantId . ", @takawaymaxno);";
$result = mysql_query($query);
$data = mysql_fetch_assoc($result);
mysql_close($connection);
return $data['maxId'];
}
示例10: __construct
/**
* Union migrate manager constructor.
*
* @param null $plugin
*/
public function __construct($plugin = null)
{
if (Plugin::loaded($plugin)) {
$this->_connectionConfig = ConnectionManager::config($this->_connectionName);
$this->_adapterName = $this->_getAdapterName($this->_connectionConfig['driver']);
$config = ['paths' => ['migrations' => UnionPlugin::migrationPath($plugin)], 'environments' => $this->_configuration()];
$this->_plugin = $plugin;
$this->_config = new Config($config);
$adapterOptions = $this->_config->getEnvironment($this->_connectionName);
$this->_adapter = $this->_setAdapter($adapterOptions);
}
}
示例11: get_product_list
public function get_product_list()
{
// make array with value is offeritems_id and text show from product table
ConnectionManager::config('default');
$conn = ConnectionManager::get('default');
$product_list = $conn->query("SELECT OfferItems.id AS `OfferItems__id`, Products.productName AS `Products__productName`" . " FROM offer_items OfferItems INNER JOIN order_items OrderItems ON OrderItems.id = (OfferItems.order_items_id)" . " INNER JOIN products Products ON Products.id = (OrderItems.products_id) LIMIT 20 OFFSET 0");
$offerItem_product_list = [];
foreach ($product_list as $prod) {
$offerItem_product_list[$prod['OfferItems__id']] = $prod['Products__productName'];
}
return $offerItem_product_list;
}
示例12: startup
/**
* {@inheritdoc}
*/
public function startup()
{
foreach (Config::get('cake_orm.datasources', []) as $name => $dataSource) {
ConnectionManager::config($name, $dataSource);
}
Cache::config(Config::get('cake_orm.cache', []));
if (!is_dir($cakeLogPath = LOG_DIR . DS . 'cake')) {
mkdir($cakeLogPath, 0777, true);
}
Log::config('queries', ['className' => 'File', 'path' => LOG_DIR . DS . 'cake' . DS, 'file' => 'queries.log', 'scopes' => ['queriesLog']]);
$this->getEventManager()->addSubscriber(new CakeORMSubscriber());
}
示例13: initialize
function initialize(Container $container)
{
parent::initialize($container);
$configs = $this->getConfigs();
// 设置数据库
foreach ($configs['datasources'] as $name => $config) {
ConnectionManager::config($name, $config);
}
// 设置缓存
foreach ($configs['cache'] as $name => $config) {
Cache::config($name, $config);
}
}
示例14: testInvalidDB
public function testInvalidDB()
{
$this->setExpectedException('Chris48s\\Searchable\\Exception\\SearchableFatalException');
//set up a SQLite DB connection - SQLite is not supported
ConnectionManager::config('invalid', ['url' => 'sqlite:///:memory:', 'timezone' => 'UTC']);
$conn = ConnectionManager::get('invalid');
//create a table in SQLite
$conn->query("CREATE TABLE `Foo` (\n `id` int(11) NOT NULL,\n `textcol` VARCHAR(255),\n PRIMARY KEY (`id`)\n );");
$table = TableRegistry::get('Foo', ['connection' => $conn]);
$table->addBehavior('Chris48s/Searchable.Searchable');
//tidy up
ConnectionManager::dropAlias('invalid');
}
示例15: get_related_products
public static function get_related_products($parent_id, $product_id)
{
ConnectionManager::config('default');
$conn = ConnectionManager::get('default');
/* $product_list = $conn->query("SELECT products.*, product_makers.products_id As ProdMakerId FROM products
INNER JOIN
product_makers ON product_makers.id = products.product_makers_id
WHERE
product_makers.users_id = (SELECT product_makers.users_id AS MakerID FROM products
LEFT JOIN
product_makers ON product_makers.id = products.product_makers_id
WHERE
products.id = '" . $product_id . "') AND products.id != '" . $product_id . "'"); */
$product_list = $conn->query("SELECT products.* FROM products WHERE products.id != '" . $product_id . "'" . " AND products.categoreys_id IN((" . "SELECT categoreys.id FROM categoreys WHERE categoreys.parent_id =(" . "SELECT categoreys.parent_id FROM categoreys WHERE categoreys.id= '" . $parent_id . "')))");
return $product_list;
}