Skip to content
Snippets Groups Projects

Issue #2991337: How to get database connection in the code? Which method is recomended?

Closed Issue #2991337: How to get database connection in the code? Which method is recomended?
Closed Oleh Vehera requested to merge issue/drupal-2991337:2991337-how-to-get into 11.x

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 225 225 * @endcode
    226 226 * if you had a connection object variable $connection available to use. See
    227 227 * also the @link container Services and Dependency Injection topic. @endlink
    228 * In Object Oriented code:
    229 * - If possible, use dependency injection to use @database service or
    230 * $container->get('database'); to inject the database connection;
    231 * - If it is not possible to use dependency injection, e.g. in a static
    232 method, use \Drupal::database();
    233 * @code
    234 * $connection = \Drupal::database();
    235 * $query = $connection->query('...');
    236 * @endcode
    237 * - If services are not yet available,
    238 * \Drupal\Core\Database\Database::getConnection() can get a database
  • quietone
  • Oleh Vehera changed target branch from 9.3.x to 11.x

    changed target branch from 9.3.x to 11.x

  • Oleh Vehera added 2584 commits

    added 2584 commits

    Compare with previous version

  • Oleh Vehera
  • Oleh Vehera resolved all threads

    resolved all threads

  • Oleh Vehera added 1 commit

    added 1 commit

    • 1ec6c875 - Apply 3 suggestion(s) to 1 file(s)

    Compare with previous version

  • Oleh Vehera
  • added 314 commits

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Oleh Vehera resolved all threads

    resolved all threads

  • Oleh Vehera added 56 commits

    added 56 commits

    Compare with previous version

  • Oleh Vehera added 53 commits

    added 53 commits

    Compare with previous version

  • Oleh Vehera added 9 commits

    added 9 commits

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading