DBI (version 0.3.0)

dbConnect: Create a connection to a DBMS.

Description

Connect to a DBMS going through the appropriate authorization procedure. Some implementations may allow you to have multiple connections open, so you may invoke this function repeatedly assigning its output to different objects. The authorization mechanism is left unspecified, so check the documentation of individual drivers for details.

Usage

dbConnect(drv, ...)

Arguments

drv
an object that inherits from DBIDriver, or a character string specifying the name of DBMS driver, e.g., "RSQLite", "RMySQL", "RPostgreSQL", or an existing DBIConnection object
...
authorization arguments needed by the DBMS instance; these typically include user, password, dbname, host, port, etc. For details see the appropriate DBIDriver.

Value

  • An object that extends DBIConnection in a database-specific manner. For instance dbConnect("MySQL") produces an object of class MySQLConnection. This object is used to direct commands to the database engine.

Details

Each driver will define what other arguments are required, e.g., "dbname" for the database name, "username", and "password".

See Also

dbDisconnect to disconnect from a database.

Examples

Run this code
if (require("RSQLite")) {
# SQLite only needs a path to the database. Other database drivers
# will require more details (like username, password, host, port etc)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
con

dbListTables(con)
dbDisconnect(con)
}

Run the code above in your browser using DataCamp Workspace