Refactor of the hacky Database class #31

Open
opened 2026-02-22 17:43:04 +01:00 by vlw · 0 comments
vlw commented 2026-02-22 17:43:04 +01:00 (Migrated from codeberg.org)

The Database class is in dire need of a refactor. We should not be relying on $_ENV variables to create a new connection, and we definitely should not use the stupid "set_credentials()" method we added to bypass it. It's ugly, and leaks connections like a bitch.

We need something that uses THE SAME connection (same instance of my MySQL library) instead of creating a new one every damn time.

The primary reason why we can't just pass the constructor arguments along to the parent class are all of the new Database() statements that we use in Database\Model. Here for example:
codeberg.org/vlw/scaffold@71a9f12b02/src/Database/Model.php (L45)

We create a new connection for each of these, we should use an existing connection instead.

The `Database` class is in dire need of a refactor. We should not be relying on `$_ENV` variables to create a new connection, and we definitely should not use the stupid ["set_credentials()"](https://codeberg.org/vlw/scaffold/src/commit/71a9f12b02569161f83f5d7725a11e2ec9eed676/src/Database/Database.php#L31-L47) method we added to bypass it. It's ugly, and leaks connections like a bitch. We need something that uses THE SAME connection (same instance of my `MySQL` library) instead of creating a new one every damn time. The primary reason why we can't just pass the constructor arguments along to the parent class are all of the `new Database()` statements that we use in `Database\Model`. Here for example: https://codeberg.org/vlw/scaffold/src/commit/71a9f12b02569161f83f5d7725a11e2ec9eed676/src/Database/Model.php#L45 We create a new connection for each of these, we should use an existing connection instead.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
vlw/scaffold#31
No description provided.