-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
LODS edited this page Mar 4, 2023
·
4 revisions
In this tutorial you will learn to make a simple setup of DB Manager.
To connect to the database, you must create a DB Manager instance. This can be by either passing the connection parameters separately to the DBManager constructor.
-- Option 1: SQLite
local conn = DBManager:new({
dialect = "sqlite",
storage = "databases/db.sqlite"
})
-- Option 2: MySQL
local conn = DBManager:new({
dialect = "mysql",
host = "localhost",
port = 3306,
username = "root",
password = "123456",
database = "test_db_manager",
})
You can use the getConnection()
method to test if the connection is OK:
-- conn was the variable used in the exemple above.
if (conn:getConnection()) then
outputDebugString("Connection has been established successfully.", 3)
else
error("Unable to connect to the database.", 2)
end
DB Manager will keep the connection by default, and use the same connection for all queries. If you need to close the connection, call conn:close()
NOTE: Once conn:close() has been called, it's impossible to open a new connection. You will need to create a new DB Manager instance to access your database again.
Last update Mar 09, 2023