MySQL
in package
Class for handling MySQL database connection using PDO.
Table of Contents
Properties
Methods
- __construct() : mixed
- MySQL class constructor.
- getConnection() : PDO|PDOException
- Gets a PDO connection to the database.
Properties
$charset
private
string
$charset
Charset for connection.
$dbname
private
string
$dbname
Database name.
$host
private
string
$host
Database host.
$password
private
string
$password
Password for connection.
$port
private
int
$port
Port for connection.
$username
private
string
$username
Username for connection.
Methods
__construct()
MySQL class constructor.
public
__construct(string $host, string $dbname, string $username, string $password[, int $port = 3306 ][, string $charset = 'utf8mb4' ]) : mixed
Parameters
- $host : string
-
Database host.
- $dbname : string
-
Database name.
- $username : string
-
Username for connection.
- $password : string
-
Password for connection.
- $port : int = 3306
-
Port for connection (default: 3306).
- $charset : string = 'utf8mb4'
-
Character set (default: utf8mb4).
getConnection()
Gets a PDO connection to the database.
public
getConnection() : PDO|PDOException
This function attempts to establish a database connection using PDO. If the connection is successful, the PDO object is returned. If an exception occurs, the PDOException object is returned.
Return values
PDO|PDOException —PDO object for database connection, or PDOException on error.