Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1413,3 +1413,22 @@ Developers who rely on these math utilities should install the new package separ

```bash
composer require planetbiru/math
```

## New Feature: PDO Connection Verification Method

A new method isPdoConnected() has been introduced to allow developers to verify not only the TCP-level connection, but also the ability of PHP to execute SQL statements on the database.

Here’s the corrected version with improved grammar and clarity:


## Bug Fix: Handle Exception in method getDatabaseCredentialsFromPdo($pdo, $driver, $dbType)

If an error occurs when executing:

```php
$dsn = $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);
```

`getDatabaseCredentialsFromPdo($pdo, $driver, $dbType)` will return an empty instance of `SecretObject`.

24 changes: 24 additions & 0 deletions src/Database/PicoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1378,4 +1378,28 @@ public function setCallbackDebugQuery($callbackDebugQuery)

return $this;
}

/**
* Checks whether the PDO connection is fully active and able to execute queries.
*
* This method not only verifies that a TCP connection to the database exists,
* but also ensures that PHP can successfully execute a simple SQL statement
* on the target database. By running `SELECT 1 + 1 AS two`, it validates
* both the connection and query execution capability.
*
* @return bool True if the connection and query execution are successful, false otherwise.
*/
public function isPdoConnected()
{
try {
$stmt = $this->databaseConnection->query("SELECT 1 + 1 AS two");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return isset($row) && isset($row['two']) && $row['two'] == 2;
} catch (PDOException $e) {
// If an error occurs, assume the connection/query is not valid
}
return false;
}


}