CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.0 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.0
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
      • Exception
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class ConnectionManager

Manages and loads instances of Connection

Provides an interface to loading and creating connection objects. Acts as a registry for the connections defined in an application.

Provides an interface for loading and enumerating connections defined in config/app.php

Namespace: Cake\Datasource

Property Summary

  • $_aliasMap protected static
    array

    A map of connection aliases.

  • $_config protected static
    array

    Configuration sets.

  • $_dsnClassMap protected static

    An array mapping url schemes to fully qualified driver class names

  • $_registry protected static
    Cake\Datasource\ConnectionRegistry

    The ConnectionRegistry used by the manager.

Method Summary

  • alias() public static

    Set one or more connection aliases.

  • config() public static

    Configure a new connection object.

  • configured() public static

    Returns an array containing the named configurations

  • drop() public static

    Drops a constructed adapter.

  • dropAlias() public static

    Drop an alias.

  • dsnClassMap() public static

    Returns or updates the DSN class map for this class

  • get() public static

    Get a connection.

  • parseDsn() public static

    Parses a DSN into a valid connection configuration

Method Detail

alias() ¶ public static

alias(string $from, string $to): void

Set one or more connection aliases.

Connection aliases allow you to rename active connections without overwriting the aliased connection. This is most useful in the testsuite for replacing connections with their test variant.

Defined aliases will take precedence over normal connection names. For example, if you alias 'default' to 'test', fetching 'default' will always return the 'test' connection as long as the alias is defined.

You can remove aliases with ConnectionManager::dropAlias().

Parameters
string $from

The connection to add an alias to.

string $to

The alias to create. $from should return when loaded with get().

Returns
void
Throws
Cake\Datasource\Exception\MissingDatasourceConfigException
When aliasing a connection that does not exist.

config() ¶ public static

config(string|array $key, array $config = null): mixed

Configure a new connection object.

The connection will not be constructed until it is first used.

Parameters
string|array $key

The name of the connection config, or an array of multiple configs.

array $config optional

An array of name => config data for adapter.

Returns
mixed
Throws
Cake\Core\Exception\Exception
When trying to modify an existing config.
See Also
\Cake\Core\StaticConfigTrait::config()

configured() ¶ public static

configured(): array

Returns an array containing the named configurations

Returns
array

drop() ¶ public static

drop(string $config): bool

Drops a constructed adapter.

If you wish to modify an existing configuration, you should drop it, change configuration and then re-add it.

If the implementing objects supports a $_registry object the named configuration will also be unloaded from the registry.

Parameters
string $config

An existing configuration you wish to remove.

Returns
bool

dropAlias() ¶ public static

dropAlias(string $name): void

Drop an alias.

Removes an alias from ConnectionManager. Fetching the aliased connection may fail if there is no other connection with that name.

Parameters
string $name

The connection name to remove aliases for.

Returns
void

dsnClassMap() ¶ public static

dsnClassMap(array|null $map = null): array

Returns or updates the DSN class map for this class

Parameters
array|null $map optional

Additions/edits to the class map to apply

Returns
array

get() ¶ public static

get(string $name, bool $useAliases = true): Cake\Database\Connection

Get a connection.

If the connection has not been constructed an instance will be added to the registry. This method will use any aliases that have been defined. If you want the original unaliased connections pass FALSE as second parameter.

Parameters
string $name

The connection name.

bool $useAliases optional

Set to false to not use aliased connections.

Returns
Cake\Database\Connection
Throws
Cake\Datasource\Exception\MissingDatasourceConfigException
When config data is missing.

parseDsn() ¶ public static

parseDsn(array $config = null): array

Parses a DSN into a valid connection configuration

This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:

$dsn = 'mysql://user:pass@localhost/database';
$config = ConnectionManager::parseDsn($dsn);

$dsn = 'Cake\Database\Driver\Mysql://localhost:3306/database?className=Cake\Database\Connection';
$config = ConnectionManager::parseDsn($dsn);

$dsn = 'Cake\Database\Connection://localhost:3306/database?driver=Cake\Database\Driver\Mysql';
$config = ConnectionManager::parseDsn($dsn);

For all classes, the value of scheme is set as the value of both the className and driver unless they have been otherwise specified.

Note that querystring arguments are also parsed and set as values in the returned configuration.

Parameters
array $config optional

An array with a url key mapping to a string DSN

Returns
array

Property Detail

$_aliasMap ¶ protected static

A map of connection aliases.

Type
array

$_config ¶ protected static

Configuration sets.

Type
array

$_dsnClassMap ¶ protected static

An array mapping url schemes to fully qualified driver class names

Type

$_registry ¶ protected static

The ConnectionRegistry used by the manager.

Type
Cake\Datasource\ConnectionRegistry
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs