G
G
GiGaBy2016-07-14 16:53:39
MySQL
GiGaBy, 2016-07-14 16:53:39

How to connect to the mysql database on a remote host in Asterisk extensions.lua?

In general, the essence of the question is, I want to rewrite extensions.conf in extensions.lua. In general, everything is clear, and everything works until I tried to connect to the mysql database.
Below is the test dialplan:

extensions = {
        deskphone = {
                ["_1XX"] = function (c,e)
                        app.NoOp("Extension "..e)
                        app.NoOp("Context "..c)
                        conn_mysql()
                end;
                ["102"] = function(context, extension)
                        app.NoOp("Hello World")
                end;

                ["101"] = function(c, e)
                        app.dial("PJSIP/"..e, 60)
                end;
        }
}

function conn_mysql()

        package.cpath = package.cpath .. ";/usr/lib/x86_64-linux-gnu/lua/5.2/luasql/?.so"

        env = assert (require"luasql.mysql".mysql())
        con = assert (env:connect("asteriskdb","root","asterisk","asterisk-db"))
        cur = assert (con:execute("SHOW TABLES"))

        row = cur:fetch ()
        while row do
          print(row)
          row = cur:fetch (row)
        end

        app.NoOp(" "..env)
        env:close()
end

The error falls out:
17ab9d83b293462e9faa4357c1314ac4.png
Although if this script is executed simply from lua (purely the function of connecting to the database and selecting tables), it works without any problems.
Ubuntu 14.04, Asterisk 13, LUA 5.2

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
silverjoe, 2016-07-15
@silverjoe

He writes to you that "Out of memory"

G
GiGaBy, 2016-07-15
@GiGaBy

It doesn't tell me anything about anything. Of course, I’m not very good at lua, but there is enough memory there, and the script works fine if it is launched without being tied to the aster. That is, it displays a list of tables in the database, and when I run this function from the dialplan, this error appears.

E
Evgeniy, 2017-11-26
@BoDRbI

Here is an example of using lua and mysql from a dial plan.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question