Asterisk mysql lookup

 

Configure MySQL Resource

res_config_mysql.conf

[general]

;dbhost = 127.0.0.1
;dbport = 3306
dbsock = /var/run/mysqld/mysqld.sock

dbname = asterisk_db
dbuser = asterisk_db
dbpass = asterisk_db

dbcharset = utf8

 ; warn, createclose, createchar
requirements=createchar

connection checking

realtime mysql status

general connected to asterisk_db on socket file /var/run/mysqld/mysqld.sock with username asterisk_db for 0 seconds.

 


Usage

extensions.conf

; mysql

; MYSQL(Connect connid dhhost dbuser dbpass dbname)
; established connection identified by ${connid}
exten => _5XX,n,MYSQL(Connect connid 127.0.0.1 asterisk asterisk asterisk)

; MYSQL(Query resultid ${connid} query-string)
; Result of query is stored in ${resultid}
exten => _5XX,n,MYSQL(Query resultid ${connid} SELECT name, goto FROM route WHERE cid='${CALLERID(number)}')

; The return fields are assigned to ${var1}, ${var2} ... ${varN} respectively.
exten => _5XX,n,MYSQL(Fetch fetchid ${resultid} name goto)

exten => _5XX,n,NoOp("We found: ${name} ${goto}")

; Frees memory
MYSQL(Clear ${resultid})

; Disconnects
MYSQL(Disconnect ${connid})

 


 

Creative Commons license icon Creative Commons license icon