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

System/Database/Database.php::loadForge returns Connection when using custom DBDriver #1225

Closed
Martin-4Spaces opened this issue Sep 18, 2018 · 3 comments

Comments

@Martin-4Spaces
Copy link

I'm extending the DBDrivers and therefore specifying my own namespace in database config. But.. Then this line will return a Connection class. I guess it should always return the Forge? :-)
4spacesdarktemplar____phpstormprojects_4spacesdarktemplar__-_____system_database_database_php__4spacesdarktemplar_

@Martin-4Spaces Martin-4Spaces changed the title System/Database/Database.php::loadForge returning Connection if using custom DBDriver System/Database/Database.php::loadForge returns Connection if using custom DBDriver Sep 18, 2018
@Martin-4Spaces Martin-4Spaces changed the title System/Database/Database.php::loadForge returns Connection if using custom DBDriver System/Database/Database.php::loadForge returns Connection when using custom DBDriver Sep 19, 2018
@jim-parry jim-parry added the waiting for info Issues or pull requests that need further clarification from the author label Oct 19, 2018
@jim-parry
Copy link
Contributor

Reading that source line, loadForge(...) should return a Forge object if the $db connection driver name doesn't contain a backslash, and a Connection object if it does.
So, no, it would not always return a Forge (generally).
If your DBDriver name always includes a namespace, then I would think that it would return a Forge.

If loadForge(...) isn't behaving as expected, can you provide some sample code? Thanks.

@Martin-4Spaces
Copy link
Author

The purpose of loadForge is "Create a new Forge instance for the current database type".
The default DBDriver name (mysql/mysqli/..) does not include namespace (no \) and therefore it will return a Forge object with \CodeIgniter\Database\ as namespace.
To use my own DBDriver I will have to specify the namespace in DBDriver name. Ex. \MyDatabaseDriver\Mysqli. Becasuse of the \ this line will return an instance of \MyDatabaseDriver\Mysqli\Connection.
The frameworks does not expect to get a Connection-object when calling loadForge and stuff starts to break down cause of that :D

I hope this explains the issue.
The solution is to replace '\Connection' with '\Forge'.

@lonnieezell
Copy link
Member

I believe that should return a Forge instance always. It looks like a flub from when I ported from CI3. Will fix.

@lonnieezell lonnieezell removed the waiting for info Issues or pull requests that need further clarification from the author label Oct 24, 2018
lonnieezell added a commit that referenced this issue Oct 24, 2018
Fix error where Forge class might not be returned. Fixes #1225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants