Skip to content

Instantly share code, notes, and snippets.

Last active Dec 2, 2017
What would you like to do?
Connecting to MySQL with Swift
public class DB {
// You'll need to update these values based on how you've set up MySQL.
let host = ""
let user = "root"
let password = "admin"
let database = "nintendo"
func databaseConnect(host: String, user: String, password: String, db: String) -> MySQL {
let mysql = MySQL() // Create an instance of MySQL to work with
let connected = mysql.connect(host: host, user: user, password: password, db: db)
guard connected else {
// verify that we have connected successfully
return mysql
return mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment