<div>It can get confusing at first but once you get the hang of it, its a breeze.</div>
<div>first take a look at: <a href="http://www.voip-info.org/wiki-Asterisk+cmd+MYSQL">http://www.voip-info.org/wiki-Asterisk+cmd+MYSQL</a></div>
<div>there is plenty of (correct)info and (working)examples on this page.</div>
<div>&nbsp;</div>
<div>you have to \escape a&nbsp;space,quote and double quote, comma and backslash - so you just write down the query the same way as it worked on the query browser and just prepend and backslash every time you see one of these characters.
</div>
<div>looking at your old query line:</div>
<div>exten =&gt; s,n,MYSQL(Query resultid ${connid} SELECT\ password\ FROM\dnislookup\ WHERE\ dnis=\&#39;${IVR-Exten}\&#39;)</div>
<div>you have a backslash but no space between FROM and dnislookup. I also dropped the quotes on the dnis=${IVR-Exten}.</div>
<div>&nbsp;</div>
<div>the other thing that might cause some confusion is the return var for each MYSQL(subcommand). to start you have the connect line which after execution returns the specific connection identifier on ${connid}. now you are ready to issue a query - the query result will be stored in ${resultid} and it will the connection id you specifiy - ${connid} in your case.
</div>
<div>once you got your resultset stored&nbsp;in ${resultid}&nbsp;you have the fetch line which is used to assign the resultset into asterisk vars. the return var in this line is ${fetchid} which lets you know if there is a row available in your resultset (1=true, 0=false), then you specify the resultset you want to work on - ${resultid} in your case.
</div>
<div>this is from your old example:</div>
<div>exten =&gt; s,n,MYSQL(Fetch fetchid ${password} password)</div>
<div>the var ${password} right after fetchid is not a resultset and should be corrected to ${resultid}.</div>
<div>&nbsp;</div>
<div>the last parameter - password is the var which will be assigned with the result.</div>
<div>to assign additional fields you simply change your query to something like SELECT password, online, owner FROM... and your fetch to MYSQL(Fetch fetchid ${resultid} password online owner).</div>
<div>&nbsp;</div>
<div>Joss.</div>
<div><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 4/14/07, <b class="gmail_sendername">Barton Fisher</b> &lt;<a href="mailto:bhfisher@icpage.com">bhfisher@icpage.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Sorry, me again..<br>I&#39;m at a loss as to why your example worked and mine didn&#39;t - I was<br>using one of the last examples I found during my searches.
<br>Can you tell me when/why I need to use the escape or quotes?&nbsp;&nbsp;Is there<br>some basic rule to follow?&nbsp;&nbsp;I&#39;m asking because there is<br>a confusing mix of examples on google search and I&#39;m not sure how to know.<br>
<br>Also, if I wish to expand the query to return additional fields (for<br>example online &amp; owner) How would I add these to query and populate the<br>variables?<br><br>Thanks<br><br>Bart<br><br>Yossi Ben Hagai wrote:
<br>&gt; That&#39;s the correct syntax:<br>&gt;<br>&gt; exten =&gt; s,1,Noop()<br>&gt; exten =&gt; s,n,MYSQL(Connect connid localhost root passw0rd dax)<br>&gt;<br>&gt; exten =&gt; s,n,MYSQL(Query resultid ${connid} SELECT\ password\ FROM\
<br>&gt; dnislookup\ WHERE\ dnis=${IVR-Exten})<br>&gt; exten =&gt; s,n,MYSQL(Fetch fetchid ${resultid} password)<br>&gt;<br>&gt; exten =&gt; s,n,MYSQL(Clear ${password})<br>&gt; exten =&gt; s,n,MYSQL(Disconnect ${connid})
<br>&gt; exten =&gt; s,n,returnpes<br>&gt;<br>&gt; On 4/14/07, *Barton Fisher* &lt;<a href="mailto:bhfisher@icpage.com">bhfisher@icpage.com</a><br>&gt; &lt;mailto:<a href="mailto:bhfisher@icpage.com">bhfisher@icpage.com</a>
&gt;&gt; wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Sorry,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; From the logs I see:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Apr 13 13:32:06 WARNING[19854] app_addon_sql_mysql.c: Identifier 0,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; identifier_type 2 not found in identifier list
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Apr 13 13:32:06 WARNING[19854] app_addon_sql_mysql.c: aMYSQL_fetch:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Invalid result identifier 0 passed<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Using this:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,1,Noop()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,MYSQL(Connect connid localhost root passw0rd dax)
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,MYSQL(Query resultid ${connid} SELECT\ password\ FROM\<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; dnislookup\ WHERE\ dnis=\&#39;${IVR-Exten}\&#39;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,MYSQL(Fetch fetchid ${password} password)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,MYSQL(Clear ${password})
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,MYSQL(Disconnect ${connid})<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; exten =&gt; s,n,return<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Bart<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Alex Balashov wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; On Fri, 13 Apr 2007, Barton Fisher said something to this effect:
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt; What wrong with this:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; Well... what is wrong with it?&nbsp;&nbsp;:-)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; I&#39;m not trying to be funny, but, what are the symptoms that it
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; doesn&#39;t work?&nbsp;&nbsp;Error output on Asterisk<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; console?&nbsp;&nbsp;Logs?&nbsp;&nbsp;Anything you<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; can provide would be helpful.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; -- Alex<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; --
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Alex Balashov &lt;<a href="mailto:sasha@presidium.org">sasha@presidium.org</a> &lt;mailto:<a href="mailto:sasha@presidium.org">sasha@presidium.org</a>&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; _______________________________________________
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; --Bandwidth and Colocation provided by <a href="http://Easynews.com">Easynews.com</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a href="http://Easynews.com">http://Easynews.com</a>&gt; --<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; asterisk-users mailing list
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; To UNSUBSCRIBE or update options visit:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; <a href="http://lists.digium.com/mailman/listinfo/asterisk-users">http://lists.digium.com/mailman/listinfo/asterisk-users</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; __________ NOD32 2187 (20070413) Information __________<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; This message was checked by NOD32 antivirus system.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; <a href="http://www.eset.com">
http://www.eset.com</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; _______________________________________________<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; --Bandwidth and Colocation provided by <a href="http://Easynews.com">
Easynews.com</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a href="http://Easynews.com">http://Easynews.com</a>&gt; --<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; asterisk-users mailing list<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; To UNSUBSCRIBE or update options visit:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://lists.digium.com/mailman/listinfo/asterisk-users">
http://lists.digium.com/mailman/listinfo/asterisk-users</a><br>&gt;<br>&gt;<br><br><br><br></blockquote></div><br>