Last active
December 2, 2017 19:15
-
-
Save kidcodely/8cbd2cd6ed0cbbe9acf9b2c40853d0ab to your computer and use it in GitHub Desktop.
Connecting to MySQL with Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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