Index Documentation

MariaDBConnection
in package
implements IDbConnection, IDbTransactions

Represents a connection with a MariaDB or MySQL database server.

Table of Contents

Interfaces

IDbConnection
Represents a connection to a database service.
IDbTransactions
Indicates supports for transactions in a database connection.

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()  : void
Enters a transaction.
close()  : void
Closes the connection and associated resources.
commit()  : void
Commits the actions done during a transaction and ends the 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.
releaseSavePoint()  : void
Releases a save point.
rollback()  : void
Rolls back to the state before a transaction start or to a specified save point.
savePoint()  : void
Creates a save point in the transaction that can be rolled back to.
setAutoCommit()  : void
Sets whether changes should be applied immediately or whether commit should always be called first.
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.

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

close()

Closes the connection and associated resources.

public close() : void

commit()

Commits the actions done during a transaction and ends the transaction.

public commit() : void

A new transaction will be started if auto-commit is disabled.

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.

releaseSavePoint()

Releases a save point.

public releaseSavePoint(string $name) : void
Parameters
$name : string

Name of the save point.

rollback()

Rolls back to the state before a transaction start or to a specified save point.

public rollback([string|null $name = null ]) : void
Parameters
$name : string|null = null

Name of the save point, null for the entire transaction.

savePoint()

Creates a save point in the transaction that can be rolled back to.

public savePoint(string $name) : void
Parameters
$name : string

Name for the save point.

setAutoCommit()

Sets whether changes should be applied immediately or whether commit should always be called first.

public setAutoCommit(bool $state) : void
Parameters
$state : bool

true if things should automatically be committed, false if not.

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.


        
On this page

Search results