Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Connection ID unknown immediately after connection #3601

Closed
lf-uraku-yuki opened this issue Sep 4, 2020 · 2 comments
Closed

Bug: Connection ID unknown immediately after connection #3601

lf-uraku-yuki opened this issue Sep 4, 2020 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@lf-uraku-yuki
Copy link
Contributor

lf-uraku-yuki commented Sep 4, 2020

Describe the bug
Immediately after connecting to DB using \Config\Database::connect('group_name'), the connID of DB cannot be obtained. You will be able to see the connID after executing some SQL. I found it when using Postgre.

CodeIgniter 4 version
4.0.4

Affected module(s)
CodeIgniter\Database\Postgre

Expected behavior, and steps to reproduce if appropriate
Execute \Config\Database::connect('group_name') to get the public connID of the returned object.

Context

  • OS: Windows 10 2004 64bit
  • Web server is [php spark server]
  • PHP version 7.4.9 x86_64 Thread Safe
@lf-uraku-yuki lf-uraku-yuki added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 4, 2020
@michalsn
Copy link
Member

michalsn commented Sep 6, 2020

This is intentional. It's made that's way to avoid unnecessary database connection. You may have database class loaded globally and an immediate connection is not always needed as we may not use the database at all for some pages. Therefore the connection takes place only when the first query is called.

If you want to connect immediately - before you run any query, just call the initialize() method.

$db = \Config\Database::connect();
$db->initialize();

@michalsn michalsn closed this as completed Sep 6, 2020
@lf-uraku-yuki
Copy link
Contributor Author

Thank you for answering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants