Difference between revisions of "Macros For MySQL Functions"

From Baranoski.ca
Jump to navigation Jump to search
(Created page with "<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;"> ; ==== MYSQL FETCH ============================================================ [macro-MYSQL...")
 
Line 1: Line 1:
 +
==To Fetch Data From MySQL==
 +
 
<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;">
 
<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;">
; ==== MYSQL FETCH ============================================================
 
 
[macro-MYSQLFETCH]
 
[macro-MYSQLFETCH]
 
 
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
 
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
 
exten => s,n,MYSQL(Query resultid ${connid} ${ARG2})
 
exten => s,n,MYSQL(Query resultid ${connid} ${ARG2})
Line 8: Line 8:
 
exten => s,n,MYSQL(Clear ${resultid})
 
exten => s,n,MYSQL(Clear ${resultid})
 
exten => s,n,MYSQL(Disconnect ${connid})
 
exten => s,n,MYSQL(Disconnect ${connid})
 +
</PRE>
 +
 +
To call the macro:
  
 +
<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;">
 +
exten => s,n,Macro(MYSQLFETCH,DNDVALUE,SELECT value FROM features WHERE name="dnd" AND subname="status")
 +
exten => s,n,GotoIf($[${DNDVALUE} = 1 ]?LINEISDND,s,1)
 +
</PRE>
  
 
; ==== MYSQL UPDATE ===========================================================
 
; ==== MYSQL UPDATE ===========================================================
 +
<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;">
 
[macro-MYSQLUPDATE]
 
[macro-MYSQLUPDATE]
 
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
 
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
 
exten => s,n,MYSQL(Query resultid ${connid} ${URIDECODE(${ARG1})})
 
exten => s,n,MYSQL(Query resultid ${connid} ${URIDECODE(${ARG1})})
 
exten => s,n,MYSQL(Disconnect ${connid})
 
exten => s,n,MYSQL(Disconnect ${connid})
 +
</PRE>
 +
 +
To call the macro:
 +
 +
<PRE style="color:white;background-color:black;font-weight:bold;font-size:1.2em;">
 +
exten => s,n,Macro(MYSQLUPDATE,${URIENCODE(UPDATE blacklist SET lastcalled=NOW(), numberofcalls=numberofcalls+1 WHERE number="${CALLERID(number)}")})
 
</PRE>
 
</PRE>

Revision as of 14:03, 13 June 2013

To Fetch Data From MySQL

[macro-MYSQLFETCH]
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
exten => s,n,MYSQL(Query resultid ${connid} ${ARG2})
exten => s,n,MYSQL(Fetch fetchid ${resultid} ${ARG1})
exten => s,n,MYSQL(Clear ${resultid})
exten => s,n,MYSQL(Disconnect ${connid})

To call the macro:

exten => s,n,Macro(MYSQLFETCH,DNDVALUE,SELECT value FROM features WHERE name="dnd" AND subname="status")
exten => s,n,GotoIf($[${DNDVALUE} = 1 ]?LINEISDND,s,1)
==== MYSQL UPDATE ===========================================================
[macro-MYSQLUPDATE]
exten => s,1,MYSQL(Connect connid localhost asterisk yourpassword asterisk)
exten => s,n,MYSQL(Query resultid ${connid} ${URIDECODE(${ARG1})})
exten => s,n,MYSQL(Disconnect ${connid})

To call the macro:

exten => s,n,Macro(MYSQLUPDATE,${URIENCODE(UPDATE blacklist SET lastcalled=NOW(), numberofcalls=numberofcalls+1 WHERE number="${CALLERID(number)}")})