[Help] How do I connect dial plan to Mysql database

Newbie needing help.

I’d like to know how to connect my dial plan to a mysql database.
The goal is to have callers who reach a particular ext have to enter a PIN in order to continue to the next priority.

I’m using Asterisk@Home version 2.5
I don’t have a programming background so most of the self help sites I see are goobly gook to me. Please understand.


exten => 11,1,Background(custom/GreetingSaysEnterPIN)
exten => 11,2,Customer enters PIN listed in PIN_NUm mysql database.
exten => 11,3,If PIN is available call goes to priority 4. If invalid PIN is entered, caller gets “Invalid account” recording.


Is it an existing Mysql database?

Hi, Ian,
The answer is no, it is not an existing database. I was thinking that after I figure out how to connect to a database, I could then create it and connect to it.

Ok next question is why ? and does it need to be sql ?

This can be done with the internal database and the dialplan very simply

The database does not need to be sql. I just thought msql because I keep seeing references to making databases using mysql. From what I have read they are supposed to be faster, better etc, etc.
I would be open to using the internal database if I can figure out how to use it.

Did you consider using Authenticate in your dialplan to prompt for a pin number?

The following example user must enter pin 1234 to contiune:

exten => 11,1,Background(custom/GreetingSaysEnterPIN)
exten => 11,2,Authenticate(1234)
exten => 11,3,Contiunue…

I did consider the example that you gave. However, I would like to have individual PINs for callers. I do not want to have the same PIN for every caller.
Thanks for the suggestion

I do have a complete system using the internal atabase that has usernumbers and pins that works with disa by changing the context of the call and allowing them to dial out. It is set up via a web gui to ease the entry of pins.


Check this application:

[code]09:12:06@forge> show application MYSQL
-= Info about application ‘MYSQL’ =-

Do several mySQLy things

MYSQL(): Do several mySQLy things
MYSQL(Connect connid dhhost dbuser dbpass dbname)
Connects to a database. Arguments contain standard MySQL parameters
passed to function mysql_real_connect. Connection identifer returned
in ${var}
MYSQL(Query resultid ${connid} query-string)
Executes standard MySQL query contained in query-string using established
connection identified by ${connection_identifier}. Result of query is
is stored in ${var}.
MYSQL(Fetch fetchid ${resultid} var1 var2 … varN)
Fetches a single row from a result set contained in ${result_identifier}.
Assigns returned fields to ${var1} … ${varn}. ${fetchid} is set TRUE
if additional rows exist in result set.
MYSQL(Clear ${resultid})
Frees memory and datastructures associated with result set.
MYSQL(Disconnect ${connid})
Disconnects from named connection to MySQL.
On exit, always returns 0. Sets MYSQL_STATUS to 0 on success and -1 on error.[/code]