title: mySQL query in C++
body: <p>I have the following code in my C++ program:</p>
  
  <pre><code>query_state = mysql_query(connection, "select * from cplpl");
  </code></pre>
  
  <p>if I want to replace the table name,cplpl, by a variable in my C++ program, how do I do it?</p>
  
  <p>basically, I've created</p>
  
  <pre><code>string tblnm="cplpl";
  </code></pre>
  
  <p>but then if I run</p>
  
  <pre><code>query_state = mysql_query(connection, "select * from tblnm");
  </code></pre>
  
  <p>it looks for the table tblnm. I tried $tblnm also like you can do in Perl, but that doesn't work either</p>
  
  <p>Is there a way I can fix this? thx!</p>
  
  <p>EDIT:
  If I rewrite this as follows:</p>
  
  <pre><code>string tblnm="test";
  string qrycd="select * from " +tblnm;
   query_state = mysql_query(connection, qrycd.c_str());
  </code></pre>
  
  <p>it works, however, if I want to add a where clause</p>
  
  <pre><code>string qrycd1="where fname like '%Bob%';";
  </code></pre>
  
  <p>and rewrite the code as</p>
  
  <pre><code>string qrycd="select * from " +tblnm +qrycd1;
   query_state = mysql_query(connection, qrycd.c_str());
  </code></pre>
  
  <p>I get an error..</p>