Asterisk app_dbodbc


This is original Brian's re-implementation of the Asterisk database using unixODBC.
This allows for easy creation of dialplan modifiers that link into a GUI with a back-end database.

Download Brian's Version (patched to work with 1.0RC1 and above)


Download modified version to work with Asterisk 1.0RC1 and above. This version is also extended by Rob Fugina (ODBCLookupCIDName, ODBCLookupBlacklist) and Jukka Laaksola (database recconnect function).


Download modified version to work with asterisk cvs-head. This version is modified by Gregory Nietsky. Also a patch for realtime.


rpm -ivh unixODBC*rpm
rpm -ivh MyODBC*rpm

cp app_dbodbc.c /usr/src/asterisk/apps/

vi /usr/src/asterisk/apps/Makefile +28
add in the end of line: app_dbodbc.so

vi /usr/src/asterisk/apps/Makefile +110
app_dbodbc.so: app_dbodbc.o
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc

cd /usr/src/asterisk
make install


This assumes using MySQL database on RedHat - will vary for other DBs & slightly for other OS's.

Configure MySQL:
  • Add a database called 'asterisk'
  • Create a user with full read/write access to this database
  • Add a table within this database called 'astdb'
  • Add 3 fields to the structure of this table: 'astfamily', 'astkey' & 'astvalue'

vi /etc/odbcinst.ini
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1

vi /etc/odbc.ini
Description = MySQL Asterisk database
Trace = Off
TraceFile = stderr
Driver = MySQL
SERVER = localhost
PORT = 3306
DATABASE = asterisk

Test ODBC:
isql -v MySQL-asterisk myusername mypassword

vi /etc/asterisk/odbc.conf


  • ODBCget(varname=family/key):
Retrieves a value from the Asterisk database and stores it in the given variable. Always returns 0. If the requested key is not found, jumps to priority n+101 if available.
  • ODBCput(family/key=value):
Stores the given value in the Asterisk database. Always returns 0.
  • ODBCdel(family/key):
Deletes a key from the Asterisk database. Always returns 0.
  • ODBCdeltree(family[/keytree]):
Deletes a family or keytree from the Asterisk database. Always returns 0.

and if you use the extented version:

  • ODBCLookupCIDName:
Looks up Caller*ID number on the the active channel in the ODBC database (family 'cidname') and sets the Caller*ID name. Does nothing if no Caller*ID was received on the channel. This is useful if you do not subscribe to Caller*ID name delivery, or if you want to change the names on some incoming calls. Always returns 0.
  • ODBCLookupBlacklist:
Looks up the Caller*ID number on the active channel in the ODBC database. If the number is found, and if there exists a priority n + 101, where 'n' is the priority of the current instance, then the channel will be setup to continue at that priority level. Otherwise, it returns 0. Does nothing if no Caller*ID was received on the channel. Example: database put blacklist name/number> 1

See also

Created by: flavour, Last modification: Fri 17 of Feb, 2006 (20:05 UTC) by lhgomes
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+