9951 explained code solutions for 126 technologies


lua-mysqlHow to connect to Mysql


mysql = require "luasql.mysql"
local pool = mysql.mysql()
local db = pool:connect('test', 'usr', 'pwd')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

test

name of the database to connect to

'usr', 'pwd'

username and password to use for Mysql connection


Usage example

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

local cursor = db:execute('SELECT NOW() as now')
row = cursor:fetch ({}, "a")
print(row.now)
output
2022-02-04 17:09:53