Documentation

Connection
in package
implements IConnection

FinalYes

Class for connecting to the MySQL database.

This class provides methods for establishing and managing connections to a MySQL database.

Table of Contents

Interfaces

IConnection
Interface for managing database connections.

Properties

$connection  : resource
$isAlive  : bool
$raw  : resource
$resource  : resource
$_connectioninfo  : object|null
$_resource  : mysqli|null

Methods

__construct()  : mixed
Connection constructor.
__get()  : mixed
Magic getter method.
Close()  : void
Closes the MySQL database connection.
Open()  : bool
Opens a connection to the MySQL database server.
Reopen()  : bool
Reopens the MySQL database connection.

Properties

$connection read-only

public resource $connection

Alias for $resource.

$isAlive read-only

public bool $isAlive

Indicates whether the connection to the MySQL server is alive.

$raw read-only

public resource $raw

The raw MySQL connection resource.

$resource read-only

public resource $resource

The MySQL connection resource.

$_connectioninfo

private object|null $_connectioninfo = null

Connection information object containing host, port, user, password, and database.

$_resource

private mysqli|null $_resource = null

The MySQL connection resource.

Methods

__construct()

Connection constructor.

public __construct(string $host, string $port, string $user, string $password[, bool $persistent = false ][, string|null $database = null ]) : mixed

Initializes a new Connection object with the provided connection information.

Parameters
$host : string

The hostname or IP address of the MySQL server.

$port : string

The port number of the MySQL server.

$user : string

The MySQL username.

$password : string

The MySQL password.

$persistent : bool = false

Whether to use a persistent connection (true) or not (false).

$database : string|null = null

(Optional) The name of the default database to connect to.

__get()

Magic getter method.

public __get(string $property) : mixed

Allows access to read-only properties such as $resource, $raw, $connection, and $isAlive.

Parameters
$property : string

The name of the property to retrieve.

Return values
mixed

Returns the value of the requested property, or null if the property does not exist.

Close()

Closes the MySQL database connection.

public Close() : void

Open()

Opens a connection to the MySQL database server.

public Open() : bool
Tags
throws
Exception

If an error occurs while establishing the connection.

Return values
bool

Returns true if the connection was successful; otherwise, false.

Reopen()

Reopens the MySQL database connection.

public Reopen() : bool

This method is an alias for Open().

Return values
bool

Returns true if the connection was successfully reopened; otherwise, false.


        
On this page

Search results