title: MySQL: searching rows with TEXT field beginning with a query
body: <p>I have a table and one of the column is TEXT type. I need to search the table for the rows with the text similar to the given string.</p>
  
  <p>As the string can be pretty long (let's say 10000 bytes) I decided that it will be enough to compare only first 20 bytes of the string. To do this search faster I created a key:</p>
  
  <pre><code>KEY `description` (`description`(20))
  </code></pre>
  
  <p>So what I want to do now is one of the following query:</p>
  
  <pre><code>SELECT * FROM `table` WHERE STRCMP(SUBSTRING(`description`,0,20),'string_to_compare') = 0
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT * FROM `table` WHERE `description` LIKE 'string_to_compare%')
  </code></pre>
  
  <p>Note that I put only one percentage sign at the end of <em>string_to_compare</em> for saying to DB that I want to compare only first bytes.</p>
  
  <p>I hope that MySQL brains will do the best to use key and not to do any extra moves.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Is there any difference which query is better? I'm personally prefer the second as it looks clearer and hopefully will be better understand by the DB engine (MyISAM).</li>
  <li>Is that correct the MySQL MyISAM will make an efficient code for these queries?</li>
  <li>How do I put '%' in the PDO's prepare statement? <code>SELECT * FROM table
  WHERE description LIKE ":text%"</code>?</li>
  </ol>