opkg update
opkg install luasql-pgsql
nano pgsql.lua
#!/usr/bin/lua
require "luasql.postgres"
env = assert(luasql.postgres())
con = assert(env:connect('mypgdatabase', 'postgres', 'password', "192.168.0.240"))
-- retrieve a cursor
cur = assert(con:execute('select username, password from login'))
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
while row do
    print(string.format("username: %s, password: %s", row.username, row.password))
    -- reusing the table of results
    row = cur:fetch (row, "a")
end
-- close everything
cur:close()
con:close()
env:close()
chmod 755 pgsql.lua
./pgsql.lua
username: sonnyyu, password: password

Comments powered by CComment