O'Reilly logo

Asterisk: The Future of Telephony by Leif Madsen, Jared Smith, Jim Van Meggelen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the Asterisk Database (AstDB)

Having fun yet? It gets even better!

Asterisk provides a powerful mechanism for storing values, called the Asterisk database (AstDB). The AstDB provides a simple way to store data for use within your dialplan.

Tip

For those of you with experience using relational databases such as PostgreSQL or MySQL, the Asterisk database is not a traditional relational database. It is a Berkeley DB Version 1 database . There are several ways to store data from Asterisk in a relational database, but this book will not delve into them.

The Asterisk database stores its data in groupings called families, with valuesidentified by keys. Within a family, a key may be used only once. For example, if we had a family called test, we could store only one value with a key called count. Each stored value must be associated with a family.

Storing Data in the AstDB

To store a new value in the Asterisk database, we use the Set() application,[43] but instead of using it to set a channel variable, we use it to set an AstDB variable. For example, to assign the count key in the test family the value of 1:

    exten => 456,1,Set(${DB(test/count)=1})

If a key named count already exists in the test family, its value will be overwritten with the new value. You can also store values from the Asterisk command line, by running the command database put family key value . For our example, you would type database put test count 1.

Retrieving Data from the AstDB

To retrieve a value from the Asterisk database ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required