lua-mysql: a mysql driver for lua

(c) 2009-19 Alacner zhang <alacner@gmail.com>
* This content is released under the MIT License.

Table of Contents

Introduction

This is a driver for lua to use mysql. You can download lua-mysql from
git, and report bug for me and i'll fix it as quickly as i can.
after download,you can install like this.
tar xzvf lua-mysql.*
cd lua-mysql.*
make
make install

Functions

require "mysql"

Public objects

create the mysql connect link handle.

mysql.version()

mysql.version()
return the lua-mysql version info, just like:
luamysql (1.0.0) - MYSQL driver
(c) 2009-19 Alacner zhang <alacner@gmail.com>
This content is released under the MIT License.

mysql.conncet(server, username, password)

Open a connection to a MySQL Server
local db, err = mysql.connect('host', 'user', 'passwd') -- if db == nil then err is the error, or db is the mysql link handle
The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.

mysql.escape_string(wanna_escape_string)

Escapes a string for use in a mysql_query

Link objects

the methods to contol the mysql link handle

db:error()

Returns the text of the error message from previous MySQL operation

db:errno()

Returns the numerical value of the error message from previous MySQL operation

db:select_db(dbname)

Select a MySQL database

db:insert_id()

Get the ID generated from the previous INSERT operation

db:set_charset(charset)

Sets the client character set

db:affected_rows()

Get number of affected rows in previous MySQL operation

db:get_server_info()

Get MySQL server info

db:get_server_version()

Get MySQL server version info
major_version*10000 + minor_version *100 + sub_version
For example, 5.1.5 is returned as 50105.

db:real_escape_string(wanna_escape_string)

Escapes special characters in a string for use in a SQL statement

db:query(sql)

Send a MySQL query
local res = db:query('select * from `table`')

db:unbuffered_query(sql)

Send an SQL query to MySQL, without fetching and buffering the result rows

db:rollback()

Rollback the current transaction.

db:close()

Close MySQL connection

Result objects

the methods to contol the mysql result handle

res:data_seek(num)

Move internal result pointer

res:num_fields()

Get number of fields in result

res:num_rows()

Get number of rows in result , first index is like lua [1]

res:fetch_row()

Get a result row as an enumerated array

res:fetch_assoc()

Fetch a result row as an associative array

res:fetch_array(MYSQL_BOTH|MYSQL_NUM|MYSQL_ASSOC)

Fetch a result row as an associative array, a numeric array, or both, default is "MYSQL_BOTH"

res:free_result()

Free result memory