-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest.lua
More file actions
89 lines (74 loc) · 2 KB
/
test.lua
File metadata and controls
89 lines (74 loc) · 2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "mysql"
require "print_r"
local db, err = mysql.connect('localhost', 'root', 'kernel')
print(db)
print(err)
print(db:select_db('testdb'))
print(db:set_charset("utf-8"))
--os.exit();
print(db:query([[
CREATE TABLE IF NOT EXISTS `table` (
`id` bigint(20) NOT NULL auto_increment,
`hits` int(10) NOT NULL default '0',
`time` varchar(255) NOT NULL,
`col1` varchar(255) NOT NULL,
`col2` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
]]))
print(db:query("insert `table` (`hits`,`time`,`col1`,`col2`) values (10000, 33333, '天使', 'hehe')"))
print(db:insert_id())
print(db:affected_rows())
print(db:query("insert `table` (`dhits`,`time`,`col1`,`col2`) values (10000, 33333, '天使', 'hehe')"))
print(db:affected_rows())
print(mysql.escape_string('哈哈"'))
print(db:real_escape_string([['哈哈`"'\n]]))
os.exit();
local rs = db:query("select * from `table`")
--local rs = db:query("select * from `table` limit 30")
--local rs = db:unbuffered_query("select * from `table`")
print(rs:num_fields())
print(rs:num_rows())
--os.exit();
print('------ row ----------')
local row = rs:fetch_row()
print_r(row)
print('------ assoc ----------')
local row = rs:fetch_assoc()
print_r(row)
print('------array MYSQL_BOTH----------')
local row = rs:fetch_array("MYSQL_BOTH")
print_r(row)
print('------array MYSQL_ASSOC----------')
local row = rs:fetch_array("MYSQL_ASSOC")
print_r(row)
print('------array MYSQL_NUM----------')
local row = rs:fetch_array("MYSQL_NUM")
print_r(row)
print('------array----------')
local row = rs:fetch_array()
print_r(row)
--os.exit()
while row do
print_r(row)
--row = rs:fetch_array("MYSQL_NUM")
row = rs:fetch_array("MYSQL_BOTH")
--row = rs:fetch_array("MYSQL_ASSOC")
end
print(mysql.version());
--[[
print('----row------------')
local row = rs:fetch_row()
while row do
print_r(row)
row = rs:fetch_row()
end
--]]
--[[
print('--------assoc--------')
local row = rs:fetch_assoc()
while row do
print_r(row)
row = rs:fetch_assoc()
end
--]]