ODBC Example

From FreeSWITCH Wiki
Jump to: navigation, search

JavaScript ODBC Example

 var db = new ODBC("dsnName", "username", "password");
 var sql = "select * from users";


 if (!db.query(sql))
   session.hangup(); //might want to say something nice instead.

 while (db.nextRow())
   row = db.getData();
   console_log("debug", "UserName: " + row["user_name"]);


If you see get an error message like this:

  [ERR] mod_spidermonkey.c:2697 js_api_use() Error loading ODBC
  [ERR] test-odbc.js:3 mod_spidermonkey()  ReferenceError: ODBC is not defined

Ensure that the mod_spidermonkey_odbc module is installed and successfully loaded at start up (see: Mod_spidermonkey_odbc). mod_spidermonkey_odbc (and all other spidermonkey extensions) is configured to load from the spidermonkey.conf.xml.

See Also