9951 explained code solutions for 126 technologies


lua-mysqlHow to get number of rows from Mysql


mysql = require "luasql.mysql"
local pool = mysql.mysql()
local db = pool:connect('test', 'usr', 'pwd')

local cursor = db:execute('SELECT * FROM test')
local num = cursor:numrows()ctrl + c
require "luasql.mysql"

includes mysql module to work with database

mysql.mysql()

init Mysql connection

pool:connect

connect to Mysql server based on specified credentials

db:execute

executes given query and returns cursor to iterate through results

cursor

cursor to manipulate result set

:numrows()

returns number of rows in a result set


Usage example

mysql = require "luasql.mysql"
local pool = mysql.mysql()
local db = pool:connect('test', 'usr', 'pwd')

local cursor = db:execute('SELECT * FROM test')
local num = cursor:numrows()

print(num)
output
16