-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.lua
More file actions
57 lines (52 loc) · 1.17 KB
/
example.lua
File metadata and controls
57 lines (52 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
include "promise.lua"
require "gluamysql"
local config = {
host = "localhost",
username = "username",
password = "password",
database = "test",
}
mysql.connect(
config.host,
config.username,
config.password,
config.database
)
:next(function(db)
print("CONNECTED TO DATABASE: ", db)
db:query("SELECT 1 as number")
:next(function(data)
print "SELECTED DATA:"
PrintTable(data)
end)
:catch(function(err)
print("ERROR SELECTING 1: " .. err)
end)
db:prepare("SELECT ? as data")
:next(function(stmt)
print("PREPARED: ", stmt)
print("PARAMETER COUNT", stmt:parametercount())
stmt:execute "76561198050165746"
:next(function(t)
print("SELECTED 76561198050165746: ", t[1].data)
PrintTable(t)
end)
:catch(function(err)
print("FAILED SELECTING 76561198050165746: " .. err)
end)
stmt:execute "4"
:next(function(t)
print("SELECTED 4: ", t[1].data)
PrintTable(t)
end)
:catch(function(err)
print("FAILED SELECTING 4: " .. err)
end)
end)
:catch(function(err)
print("PREPARE ERR", err)
end)
end)
:catch(function(err)
print("CONNECTION ERROR" .. err)
end)