You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates a MySQL connection object. In case of failures, returns `nil` and a string describing the error.
138
176
177
+
[Back to TOC](#table-of-contents)
178
+
139
179
connect
140
180
-------
141
181
`syntax: ok, err = db:connect(options)`
@@ -165,12 +205,16 @@ The `options` argument is a Lua table holding the following keys:
165
205
166
206
Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method.
167
207
208
+
[Back to TOC](#table-of-contents)
209
+
168
210
set_timeout
169
211
----------
170
212
`syntax: db:set_timeout(time)`
171
213
172
214
Sets the timeout (in ms) protection for subsequent operations, including the `connect` method.
@@ -183,6 +227,8 @@ In case of success, returns `1`. In case of errors, returns `nil` with a string
183
227
184
228
Only call this method in the place you would have called the `close` method instead. Calling this method will immediately turn the current `resty.mysql` object into the `closed` state. Any subsequent operations other than `connect()` on the current objet will return the `closed` error.
185
229
230
+
[Back to TOC](#table-of-contents)
231
+
186
232
get_reused_times
187
233
----------------
188
234
`syntax: times, err = db:get_reused_times()`
@@ -191,6 +237,8 @@ This method returns the (successfully) reused times for the current connection.
191
237
192
238
If the current connection does not come from the built-in connection pool, then this method always returns `0`, that is, the connection has never been reused (yet). If the connection comes from the connection pool, then the return value is always non-zero. So this method can also be used to determine if the current connection comes from the pool.
193
239
240
+
[Back to TOC](#table-of-contents)
241
+
194
242
close
195
243
-----
196
244
`syntax: ok, err = db:close()`
@@ -199,6 +247,8 @@ Closes the current mysql connection and returns the status.
199
247
200
248
In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error.
201
249
250
+
[Back to TOC](#table-of-contents)
251
+
202
252
send_query
203
253
----------
204
254
`syntax: bytes, err = db:send_query(query)`
@@ -209,6 +259,8 @@ Returns the bytes successfully sent out in success and otherwise returns `nil` a
209
259
210
260
You should use the [read_result](#read_result) method to read the MySQL replies afterwards.
@@ -257,6 +311,8 @@ This is a shortcut for combining the [send_query](#send_query) call and the firs
257
311
258
312
You should always check if the `err` return value is `again` in case of success because this method will only call [read_result](#read_result) only once for you. See also [Multi-Resultset Support](#multi-resultset-support).
259
313
314
+
[Back to TOC](#table-of-contents)
315
+
260
316
server_ver
261
317
----------
262
318
`syntax: str = db:server_ver()`
@@ -265,6 +321,8 @@ Returns the MySQL server version string, like `"5.1.64"`.
265
321
266
322
You should only call this method after successfully connecting to a MySQL server, otherwise `nil` will be returned.
267
323
324
+
[Back to TOC](#table-of-contents)
325
+
268
326
set_compact_arrays
269
327
------------------
270
328
`syntax: db:set_compact_arrays(boolean)`
@@ -273,6 +331,8 @@ Sets whether to use the "compact-arrays" structure for the resultsets returned b
273
331
274
332
This method was first introduced in the `v0.09` release.
275
333
334
+
[Back to TOC](#table-of-contents)
335
+
276
336
SQL Literal Quoting
277
337
===================
278
338
@@ -286,6 +346,8 @@ Here is an example:
286
346
localsql="select * from users where name = " ..quoted_name
287
347
```
288
348
349
+
[Back to TOC](#table-of-contents)
350
+
289
351
Multi-Resultset Support
290
352
=======================
291
353
@@ -343,6 +405,8 @@ This code snippet will produce the following response body data:
343
405
result #2: [{"2":"2"}]
344
406
result #3: [{"3":"3"}]
345
407
408
+
[Back to TOC](#table-of-contents)
409
+
346
410
Debugging
347
411
=========
348
412
@@ -357,6 +421,8 @@ It is usually convenient to use the [lua-cjson](http://www.kyne.com.au/~mark/sof
357
421
end
358
422
```
359
423
424
+
[Back to TOC](#table-of-contents)
425
+
360
426
Automatic Error Logging
361
427
=======================
362
428
@@ -368,6 +434,8 @@ handling in your own Lua code, then you are recommended to disable this automati
368
434
lua_socket_log_errors off;
369
435
```
370
436
437
+
[Back to TOC](#table-of-contents)
438
+
371
439
Limitations
372
440
===========
373
441
@@ -382,6 +450,8 @@ You should always initiate `resty.mysql` objects in function local
382
450
variables or in the `ngx.ctx` table. These places all have their own data copies for
383
451
each request.
384
452
453
+
[Back to TOC](#table-of-contents)
454
+
385
455
Installation
386
456
============
387
457
@@ -410,19 +480,27 @@ tree to ngx_lua's LUA_PATH search path, as in
410
480
Ensure that the system account running your Nginx ''worker'' proceses have
411
481
enough permission to read the `.lua` file.
412
482
483
+
[Back to TOC](#table-of-contents)
484
+
413
485
Community
414
486
=========
415
487
488
+
[Back to TOC](#table-of-contents)
489
+
416
490
English Mailing List
417
491
--------------------
418
492
419
493
The [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers.
420
494
495
+
[Back to TOC](#table-of-contents)
496
+
421
497
Chinese Mailing List
422
498
--------------------
423
499
424
500
The [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers.
425
501
502
+
[Back to TOC](#table-of-contents)
503
+
426
504
Bugs and Patches
427
505
================
428
506
@@ -431,6 +509,8 @@ Please submit bug reports, wishlists, or patches by
431
509
1. creating a ticket on the [GitHub Issue Tracker](http://github.com/agentzh/lua-resty-mysql/issues),
432
510
1. or posting to the [OpenResty community](http://wiki.nginx.org/HttpLuaModule#Community).
433
511
512
+
[Back to TOC](#table-of-contents)
513
+
434
514
TODO
435
515
====
436
516
@@ -440,11 +520,15 @@ TODO
440
520
* implement MySQL server prepare and execute packets.
441
521
* implement the data compression support in the protocol.
@@ -462,6 +546,8 @@ Redistribution and use in source and binary forms, with or without modification,
462
546
463
547
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
464
548
549
+
[Back to TOC](#table-of-contents)
550
+
465
551
See Also
466
552
========
467
553
* the ngx_lua module: http://wiki.nginx.org/HttpLuaModule
@@ -470,3 +556,5 @@ See Also
470
556
* the [lua-resty-redis](https://github.com/agentzh/lua-resty-redis) library
471
557
* the ngx_drizzle module: http://wiki.nginx.org/HttpDrizzleModule
0 commit comments