Skip to content

Instantly share code, notes, and snippets.

@kidcodely
Last active December 2, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidcodely/8cbd2cd6ed0cbbe9acf9b2c40853d0ab to your computer and use it in GitHub Desktop.
Save kidcodely/8cbd2cd6ed0cbbe9acf9b2c40853d0ab to your computer and use it in GitHub Desktop.
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