[Freeswitch-users] how to retrive data from mysql ODBC in chat.lua script ?

Steven Ayre steveayre at gmail.com
Tue Aug 12 18:23:14 MSD 2014


Scope - row only exists inside the function since it's a function argument


On 12 August 2014 08:58, Shabbir abbasi <shabbirabbasi92 at gmail.com> wrote:

> i am  testing  a script      new_chat.lua    script is below
>
> #!/usr/bin/lua
> local dbh = freeswitch.Dbh("odbc://dbname:db_username:db_passwd") --
> connect to ODBC database
> assert(dbh:connected()) -- exits the script if we didn't connect properly
>
> if dbh:connected() == false then
>    freeswitch.consoleLog("ALERT", "lua cannot connect to database" .. dsn
> .. "\n");
> end
>
> sql_query    = "SELECT * FROM cc_card WHERE id ='197'"
> dbh:query(sql_query ,function(row)
> for key, val in pairs(row) do
> key = val
> end
>  freeswitch.consoleLog("INFO"," inside  QUERY lastname = " .. row.lastname
> .. "\n");
> freeswitch.consoleLog("INFO"," inside  QUERY  redial = " .. row.redial ..
> "\n");
> end)
>
> freeswitch.consoleLog("INFO"," outside  QUERY  lastname = " ..
> row.lastname .. "\n");
> freeswitch.consoleLog("INFO","  outside  QUERY    redial = " .. row.redial
> .. "\n");
>
> freeswitch.consoleLog("INFO"," outside  QUERY  lastname = " .. lastname ..
> "\n");
> freeswitch.consoleLog("INFO","  outside  QUERY    redial = " .. redial ..
> "\n");
>
> dbh:release() -- optional
>
> but here is some problum    in this script  inside query lines are
> working  but outside query lines  are not working  WHY  ??
> any suggestions are very wellcome
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20140812/8ed4cedd/attachment.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list