Index Documentation

MariaDbConnection
in package
implements DbConnection

Represents a connection with a MariaDB or MySQL database server.

Table of Contents

Interfaces

DbConnection
Represents a connection to a database service.

Constants

REFRESH_GRANT  = MYSQLI_REFRESH_GRANT
Refresh grant tables.
REFRESH_HOSTS  = MYSQLI_REFRESH_HOSTS
Refreshes the hosts cache, like the FLUSH HOSTS; statement.
REFRESH_LOG  = MYSQLI_REFRESH_LOG
Flushes logs, like the FLUSH LOGS; statement.
REFRESH_MASTER  = MYSQLI_REFRESH_MASTER
Removes binary log files listed in the binary log index and truncates the index file on master replication servers, like the RESET MASTER; statement.
REFRESH_SLAVE  = MYSQLI_REFRESH_SLAVE
Resets information about the master server and restarts on slave replication servers, like the RESET SLAVE; statement.
REFRESH_STATUS  = MYSQLI_REFRESH_STATUS
Refresh the status variables, like the FLUSH STATUS; statement.
REFRESH_TABLES  = MYSQLI_REFRESH_TABLES
Refresh tables, like the FLUSH TABLES; statement.
REFRESH_THREADS  = MYSQLI_REFRESH_THREADS
Flushes the thread cache.

Methods

__construct()  : MariaDbConnection
Creates a new instance of MariaDbConnection.
__destruct()  : mixed
Closes the connection and associated resources.
beginTransaction()  : DbTransaction
Begins a transaction.
execute()  : int|string
Executes a statement and returns how many rows are affected.
getAffectedRows()  : int|string
Gets the number of rows affected by the last operation.
getCharacterSet()  : string
Gets the name of the currently active character set.
getCharacterSetInfo()  : MariaDbCharacterSetInfo
Returns info about the currently character set and collation.
getLastErrorCode()  : int
Gets the last error code.
getLastErrors()  : array<string|int, MariaDbWarning>
Gets a list of errors from the last command.
getLastErrorString()  : string
Gets the last error string.
getLastFieldCount()  : int
Gets the number of columns for the last query.
getLastInsertId()  : int|string
Returns the ID of the last inserted row.
getServerVersion()  : string
Gets the version of the server.
getSQLState()  : string
Gets the current SQL State of the connection.
getThreadId()  : int
Gets the thread ID for the current connection.
getWarningCount()  : int
Returns the number of warnings for the last query.
getWarnings()  : array<string|int, MariaDbWarning>
Gets list of warnings.
killThread()  : bool
Asks the server to kill a thread.
ping()  : bool
Sends a keep alive request to the server, or tries to reconnect if it has gone down.
prepare()  : MariaDbStatement
Prepares a statement for execution and returns a database statement instance.
query()  : MariaDbResult
Executes a statement and returns a database result instance.
refresh()  : void
Runs various refresh operations, see the REFRESH_ constants for the flags.
setCharacterSet()  : void
Switch to a different character set.
switchDatabase()  : void
Switches the default database for this connection.
switchUser()  : void
Switches the connection to a different user and default database.
throwLastError()  : never
Throws the last error as a RuntimeException.

Constants

REFRESH_GRANT

Refresh grant tables.

public int REFRESH_GRANT = MYSQLI_REFRESH_GRANT

REFRESH_HOSTS

Refreshes the hosts cache, like the FLUSH HOSTS; statement.

public int REFRESH_HOSTS = MYSQLI_REFRESH_HOSTS

REFRESH_LOG

Flushes logs, like the FLUSH LOGS; statement.

public int REFRESH_LOG = MYSQLI_REFRESH_LOG

REFRESH_MASTER

Removes binary log files listed in the binary log index and truncates the index file on master replication servers, like the RESET MASTER; statement.

public mixed REFRESH_MASTER = MYSQLI_REFRESH_MASTER

REFRESH_SLAVE

Resets information about the master server and restarts on slave replication servers, like the RESET SLAVE; statement.

public int REFRESH_SLAVE = MYSQLI_REFRESH_SLAVE

REFRESH_STATUS

Refresh the status variables, like the FLUSH STATUS; statement.

public int REFRESH_STATUS = MYSQLI_REFRESH_STATUS

REFRESH_TABLES

Refresh tables, like the FLUSH TABLES; statement.

public int REFRESH_TABLES = MYSQLI_REFRESH_TABLES

REFRESH_THREADS

Flushes the thread cache.

public int REFRESH_THREADS = MYSQLI_REFRESH_THREADS

Methods

__destruct()

Closes the connection and associated resources.

public __destruct() : mixed

execute()

Executes a statement and returns how many rows are affected.

public execute(string $query) : int|string

Does not request results back from the database and thus should have better performance if the consumer doesn't care about them.

Parameters
$query : string

SQL query to execute.

Return values
int|string

Number of rows affected by the query.

getAffectedRows()

Gets the number of rows affected by the last operation.

public getAffectedRows() : int|string
Return values
int|string

Number of rows affected by the last operation.

getCharacterSet()

Gets the name of the currently active character set.

public getCharacterSet() : string
Return values
string

Name of the character set.

getLastErrorCode()

Gets the last error code.

public getLastErrorCode() : int
Return values
int

Last error code.

getLastErrorString()

Gets the last error string.

public getLastErrorString() : string
Return values
string

Last error string.

getLastFieldCount()

Gets the number of columns for the last query.

public getLastFieldCount() : int
Return values
int

getLastInsertId()

Returns the ID of the last inserted row.

public getLastInsertId() : int|string
Return values
int|string

Last inserted ID.

getServerVersion()

Gets the version of the server.

public getServerVersion() : string
Return values
string

Version of the server.

getSQLState()

Gets the current SQL State of the connection.

public getSQLState() : string
Return values
string

Current SQL State.

getThreadId()

Gets the thread ID for the current connection.

public getThreadId() : int
Return values
int

Thread ID.

getWarningCount()

Returns the number of warnings for the last query.

public getWarningCount() : int
Return values
int

Amount of warnings.

killThread()

Asks the server to kill a thread.

public killThread(int $threadId) : bool
Parameters
$threadId : int

ID of the thread that should be killed.

Return values
bool

true if the thread was killed, false if not.

ping()

Sends a keep alive request to the server, or tries to reconnect if it has gone down.

public ping() : bool
Return values
bool

true if the keep alive was successful, false if the server is Gone.

prepare()

Prepares a statement for execution and returns a database statement instance.

public prepare(string $query) : MariaDbStatement
Parameters
$query : string

SQL query to prepare.

Return values
MariaDbStatement

A database statement.

query()

Executes a statement and returns a database result instance.

public query(string $query) : MariaDbResult
Parameters
$query : string

SQL query to execute.

Return values
MariaDbResult

A database result.

refresh()

Runs various refresh operations, see the REFRESH_ constants for the flags.

public refresh(int $flags) : void
Parameters
$flags : int

A bitset of REFRESH_ flags.

setCharacterSet()

Switch to a different character set.

public setCharacterSet(string $charSet) : void
Parameters
$charSet : string

Name of the new character set.

Tags
throws
InvalidArgumentException

Switching to new character set failed.

switchDatabase()

Switches the default database for this connection.

public switchDatabase(string $database) : void
Parameters
$database : string

New default database.

Tags
throws
RuntimeException

If the database switch failed.

switchUser()

Switches the connection to a different user and default database.

public switchUser(string $userName, string $password[, string|null $database = null ]) : void
Parameters
$userName : string

New user name.

$password : string

New password.

$database : string|null = null

New default database.

Tags
throws
RuntimeException

If the user switch action failed.

throwLastError()

Throws the last error as a RuntimeException.

public throwLastError() : never
Tags
throws
RuntimeException

Based on the last error code and string.

Return values
never

        
On this page

Search results