Class Connection

A class representing a database connection.

class Connection ;

If you are using Vibe.d, consider using MySQLPool instead of creating a new Connection directly. That will provide certain benefits, such as reusing old connections and automatic cleanup (no need to close the connection when done).

// Suggested usage:

{
	auto con = new Connection("host=localhost;port=3306;user=joe;pwd=pass123;db=myappsdb");
	scope(exit) con.close();

	// Use the connection
	...
}

Constructors

NameDescription
this Construct opened connection.

Properties

NameTypeDescription
charSet[get] ubyteCurrent character set
closed[get] boolCheck whether this Connection is still connected to the server, or if the connection has been closed.
currentDB[get] stringCurrent database
hasPending[get] boolGets whether anything (rows, headers or binary) is pending. New commands cannot be sent on a conncection while anything is pending.
lastCommandID[get] ulongThis gets incremented every time a command is issued or results are purged, so a ResultRange can tell whether it's been invalidated.
lastInsertID[get] ulongAfter a command that inserted a row into a table with an auto-increment ID column, this method allows you to retrieve the last insert ID.
protocol[get] ubyteReturn the in-force protocol number
resultFieldDescriptions[get] FieldDescription[]Gets the result header's field descriptions.
rowsPending[get] boolGets whether rows are pending
serverCapabilities[get] uintServer capability flags
serverStatus[get] ushortServer status
serverVersion[get] stringServer version
socketType[get] MySQLSocketTypeSocket type being used

Methods

NameDescription
acquire Used by Vibe.d's ConnectionPool, ignore this.
amOwner Used by Vibe.d's ConnectionPool, ignore this.
close Explicitly close the connection.
enableMultiStatements Enable multiple statement commands
getNextRow Get the next Row of a pending result set.
isOwner Used by Vibe.d's ConnectionPool, ignore this.
parseConnectionString Parses a connection string of the form "host=localhost;port=3306;user=joe;pwd=pass123;db=myappsdb"
pingServer Check the server status
purgeResult Flush any outstanding result set elements.
reconnect Reconnects to the server using the same connection settings originally used to create the Connection.
refreshServer Refresh some feature(s) of the server.
release Used by Vibe.d's ConnectionPool, ignore this.
selectDB Select a current database.
serverStats Get a textual report on the server status.