this isn’t a direct answer to your query, but an example of an inline MySQL table lookup for you to look at. you can use the bits you need to perform the DB lookup appropriate to you.
; MYSQL experiment
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playback(allison7/please-enter-your)
exten => s,4,Playback(extension)
exten => s,5,Read(fromext|then-press-pound)
exten => s,6,Wait(1)
exten => s,7,Playback(ent-target-attendant)
exten => s,8,Read(toext|then-press-pound)
exten => s,9,Wait(1)
exten => s,10,Playback(please-enter-your)
exten => s,11,Playback(vm-password)
exten => s,12,Playback(then-press-pound)
exten => s,13,Read(extsecret)
exten => s,14,Wait(1)
; change the next line to match your MySQL account details
exten => s,15,MYSQL(Connect connid localhost username password asterisk)
;next line should be all on one line !!!
exten => s,16,MYSQL(Query resultid ${connid} SELECT\ `data`\ FROM\ `sip`\ WHERE\ `id`=${fromext}\ AND\ `keyword`=\"secret"\)
exten => s,17,MYSQL(Fetch foundRow ${resultid} mysecret)
exten => s,18,MYSQL(Clear ${resultid})
exten => s,19,MYSQL(Disconnect ${connid})
exten => s,20,NoOp(${extsecret})
exten => s,21,GotoIf($["${mysecret}" = "${extsecret}"]?22:32)
exten => s,22,Playback(auth-thankyou)
exten => s,23,DBput(CF/${fromext}=${toext})
exten => s,24,Playback(call-fwd-unconditional)
exten => s,25,Playback(for)
exten => s,26,Playback(extension)
exten => s,27,SayDigits(${fromext})
exten => s,28,Playback(is-set-to)
exten => s,29,SayDigits(${toext})
exten => s,30,Playback(goodbye)
exten => s,31,Macro(hangupcall)
exten => s,32,Playback(auth-incorrect)
exten => s,33,Goto(s,13)
exten => h,1,Hangup()