Function Connection.this
Construct opened connection.
Throws mysql
upon failure to connect.
If you are using Vibe.d, consider using mysql
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
...
}
Prototypes
this(
string host,
string user,
string pwd,
string db,
ushort port = cast(ushort)3306u,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
this(
MySQLSocketType socketType,
string host,
string user,
string pwd,
string db,
ushort port = cast(ushort)3306u,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
this(
std .socket .TcpSocket function(string, ushort) openSocket,
string host,
string user,
string pwd,
string db,
ushort port = cast(ushort)3306u,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
this(
string cs,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
this(
MySQLSocketType socketType,
string cs,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
this(
std .socket .TcpSocket function(string, ushort) openSocket,
string cs,
SvrCapFlags capFlags = cast(SvrCapFlags)33293u
);
Parameters
Name | Description |
---|---|
cs | A connection string of the form "host=localhost;user=user;pwd=password;db=mysqld" (TODO: The connection string needs work to allow for semicolons in its parts!) |
socketType | Whether to use a Phobos or Vibe.d socket. Default is Phobos, unless -version=Have_vibe_d_core is used. |
openSocket | Optional callback which should return a newly-opened Phobos or Vibe.d TCP socket. This allows custom sockets to be used, subclassed from Phobos's or Vibe.d's sockets. |
host | An IP address in numeric dotted form, or as a host name. |
user | The user name to authenticate. |
password | Users password. |
db | Desired initial database. |
capFlags | The set of flag bits from the server's capabilities that the client requires |