Skip to content

Instantly share code, notes, and snippets.

@kidcodely
Last active Dec 2, 2017
Embed
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 = "127.0.0.1"
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
print(mysql.errorMessage())
return mysql
}
return mysql
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment