Opening a database

suggest change

Opening a database is database-specific. Here are examples for some databases. sql.Open checks its arguments and returns a handle; the connection is made later, when the program calls a method such as Ping or Query.

Sqlite 3

file := "path/to/file"
db_, err := sql.Open("sqlite3", file)
if err != nil {
    panic(err)
}

MySql

dsn := "mysql_username:CHANGEME@tcp(localhost:3306)/dbname"
db, err := sql.Open("mysql", dsn)
if err != nil {
    panic(err)
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents