Class Connection
A class representing a database connection.
If you are using Vibe.d, consider using mysql.pool.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
Name | Description |
this
(host, user, pwd, db, port, capFlags)
|
Construct opened connection.
|
Properties
Name | Type | Description |
charSet [get]
|
ubyte | Current character set
|
closed [get]
|
bool | Check whether this Connection is still connected to the server, or if
the connection has been closed.
|
currentDB [get]
|
string | Current database
|
hasPending [get]
|
bool | Gets whether anything (rows, headers or binary) is pending.
New commands cannot be sent on a connection while anything is pending
(the pending data will automatically be purged.)
|
lastCommandID [get]
|
ulong | This gets incremented every time a command is issued or results are purged,
so a mysql.result.ResultRange can tell whether it's been invalidated.
|
lastInsertID [get]
|
ulong | After 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]
|
ubyte | Return the in-force protocol number.
|
resultFieldDescriptions [get]
|
FieldDescription[] | Gets the result header's field descriptions.
|
rowsPending [get]
|
bool | Gets whether rows are pending.
|
serverCapabilities [get]
|
uint | Server capability flags
|
serverStatus [get]
|
ushort | Server status
|
serverVersion [get]
|
string | Server version
|
socketType [get]
|
mysql.protocol.sockets.MySQLSocketType | Socket type being used, Phobos or Vibe.d
|
Methods
Name | Description |
close
()
|
Explicitly close the connection.
|
enableMultiStatements
(on)
|
Enable multiple statement commands.
|
isRegistered
(prepared)
|
Is the given statement registered on this connection as a prepared statement?
|
parseConnectionString
(cs)
|
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
(flags)
|
Refresh some feature(s) of the server.
|
register
(prepared)
|
Manually register a prepared statement on this connection.
|
release
(prepared)
|
Manually release a prepared statement on this connection.
|
releaseAll
()
|
Manually release all prepared statements on this connection.
|
selectDB
(dbName)
|
Select a current database.
|
serverStats
()
|
Get a textual report on the server status.
|