Tutorial: Connecting Databases with Quorum
This tutorial shows us how to connect our database inside of Quorum StudioConnecting Our Database with Quorum
So far, using the MySQL command line, we have successfully created a database inside our database. We can finally start to connect the database we have created inside of Quorum Studio! Note that for these series of tutorials, we will need to work externally using MySQL and Quorum Studio. Online IDEs currently do not support a database feature. We need to make sure that we have both software running for the connection to work.
Now, we will be referencing the Database library and using the Connect(text location, text database, text username, text password) action in order for Quorum to find our database in our system. Using databases is an advanced topic in computer science, typically taught at the junior or senior level in an undergraduate college sequence. As such, keep in mind that for those just starting programming, we recommend starting with the programming tutorials, not this one, to get started.
To be able to use this function, we would need to create a database object. Similar to many objects, we initiate it like a variable where we have our object name. For this tutorial, let us call our database object database. The code then looks like so:
use Libraries.Data.Database.Database
Database database
Below we have a table of how the actions and objects we use to connect our database.
Action / Object | Description | Usage |
---|---|---|
Database databaseName | The database object used to create and modify our database | Database database |
Connect(text location, text database, text username, text password) | This action attempts to create a connection to a database using the given parameters. The following are what each parameter is required: text location: The location of the database. A common location is "localhost." text database: The name of the database text username: The name of the user text password: The password for the user | databaseName:Connect("localhost", "myDatabase","root","awesomePassword1234") |
Now that we have our database object created, we can use the Connect action to login to our database. For this step, parameters may differ on user and password name, but we should have the same database name, myfirstdatabase and location, localhost.
database:Connect("localhost", "myfirstdatabase", "root", "CoolPassword1234")
If we want to confirm that our database is connected, we can confirm calling the action IsConnected() with our object which will return true if it is connected. Below is the full code of connecting our database.
use Libraries.Data.Database.Database
Database database
database:Connect("localhost", "myfirstdatabase", "root", "CoolPassword1234")
output database:IsConnected()
Next Tutorial
In the next tutorial, we will discuss database table, which describes how to set up database table in Quorum.