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

Add establishConnection() for interoperability with future versions #230

Merged
merged 8 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ Whereas the native _PDO_ connects on instantiation, _ExtendedPdo_ does not
connect immediately. Instead, it connects only when you call a method that
actually needs the connection to the database; e.g., on `query()`.

If you want to force a connection, call the `connect()` method.
If you want to force a connection, call the `establishConnection()` method.

> Previous `connect()` method has been deprecated due to the introduction of
> ```PDO::connect()``` in [PHP 8.4](https://www.php.net/releases/8.4/en.php#pdo_driver_specific_subclasses),
> so we encourage users t0 use `establishConnection()` instead.
srjlewis marked this conversation as resolved.
Show resolved Hide resolved

```php
// does not connect to the database
Expand All @@ -42,7 +46,7 @@ $pdo = new ExtendedPdo(
$pdo->exec('SELECT * FROM test');

// explicitly forces a connection
$pdo->connect();
$pdo->establishConnection();
```

If you want to explicitly force a disconnect, call the `disconnect()` method.
Expand Down
41 changes: 41 additions & 0 deletions docs/upgrade.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
# 5.x Upgrade Notes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.x right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I meen 5.x as it is a deprecation in 5.x and adding a alias for connect() method, as the commit is targeting 5.x branch.

I need to make PR for the doc changes in 6.x which explain the new connect method.


Most changes are to provide better typing and compatability with PHP 8.1 and above.

## Deprecations

The main change is the deprecation of `ExtendedPdo::connect()` and will be changed in future versions starting with 6.x

Older Code would look like ...

```php
// does not connect to the database
$pdo = new ExtendedPdo(
'mysql:host=localhost;dbname=test',
'username',
'password'
);

// automatically connects
$pdo->exec('SELECT * FROM test');

// explicitly forces a connection
$pdo->connect();
```
... and now needs to be changed to `ExtendedPdo::establishConnection()`

```php
// does not connect to the database
$pdo = new ExtendedPdo(
'mysql:host=localhost;dbname=test',
'username',
'password'
);

// automatically connects
$pdo->exec('SELECT * FROM test');

// explicitly forces a connection
$pdo->establishConnection();
```

# 3.x Upgrade Notes

The vast majority of changes and breaks from the 2.x version are "under the
Expand Down
13 changes: 13 additions & 0 deletions src/ExtendedPdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function __construct(
*
* Connects to the database.
*
* @deprecated use establishConnection() as future versions will be using establishConnection()
*
* @return void
*/
public function connect(): void
Expand All @@ -109,6 +111,17 @@ public function connect(): void
}
}

/**
*
* alias of connect() for interoperability with future versions Aura.Sql
*
* @return void
*/
public function establishConnection(): void
{
$this->connect();
}

/**
*
* Disconnects from the database.
Expand Down
Loading