Compare
class Compare (View source)
The GenericDatabase\Helpers\Compare class provides methods for determining the type of given
database connection this class can identify the type of database connection whether it is a
resource connection or an object connection, and it can also determine the type of database
connection whether it is a resource connection or an object connection.
Example Usage:
//Using a resource-based database connection (e.g., OCI)
$ociConnection = oci_connect("username", "password", "localhost/xe");
$type = Compare::connection($ociConnection);
echo "Database type: $type";
Output: Database type: oci
//Using an object-based database connection (e.g., PDO for MySQL)
$pdoConnection = new PDO("mysql:host=localhost;dbname=database", "username", "password");
$type = Compare::connection($pdoConnection);
echo "Database type: $type";
Output: Database type: PDO mysql
//Using an unknown or invalid connection
$invalidConnection = "invalid_connection_string";
$type = Compare::connection($invalidConnection);
echo "Database type: $type";
Output: Database type: Unidentified or invalid connection type.
Main functionalities:
- Determines the type of database connection, whether it is a resource or an object connection.
- Handles various types of database connections, including PDO, MySQLi, SQLite3, and custom connection classes.
Methods:
connection($cnx): string: Determines the type of the given connection. It accepts either a resource or an object connection and returns a string representing the connection type.getResourceConnectionType($cnx): string: Determines the type of a resource-based database connection.getObjectConnectionType($cnx): string: Determines the type of an object-based database connection.
Methods
Determines the type of the given connection. It accepts either a resource or an object connection and returns a string representing the connection type.
Details
static string
connection(mixed $cnx)
Determines the type of the given connection. It accepts either a resource or an object connection and returns a string representing the connection type.