[Asterisk-Users] Re: using the MYSQL command to insert a record

Tony Mountifield tony at softins.clara.co.uk
Thu Feb 3 02:53:28 MST 2005


In article <20050203050228.44097.qmail at web31009.mail.mud.yahoo.com>,
Robert Howard <mrroberthoward at yahoo.com> wrote:
> I am trying to use the MYSQL command to insert a
> record into a database and I can't seem to get it to
> work. I can do an UPDATE with no problem.
> Here is the line in my dialplan
> exten => s,12,MYSQL(QUERY resultid ${connid} INSERT
> INTO `member` ( `id` , `member_num` , `active` )VALUES
> ('',${number}' , '1'))
> 
> Does anyone have an example of an INSERT INTO that I
> could look at?

Firstly, backticks around table and column names are not needed unless
the name has weird characters in it.

Secondly, the whole query needs single quotes around it.

Thirdly, single quotes within the query need \-escaping.

Here's a working example which updates a database on hangup:

exten => h,1,MYSQL(Connect conn localhost username password dbname)
exten => h,2,MYSQL(Query res ${conn} 'INSERT INTO responses(adv_id,resp_callerid,resp_file,resp_created) VALUES(${advertid},\'${CALLERIDNUM}\',\'${RECORDED_FILE}\',NOW())')
exten => h,3,MYSQL(Disconnect ${conn})

Hope this helps!
Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org



More information about the asterisk-users mailing list