title: PHP PDO & SQL Search wildcard bind parameters
body: <p>I am trying to create a search function for a site and have created the sql code, which was generated from PHPMYADMIN, see below; </p>
  
  <pre><code>$sql = "SELECT * FROM `bg85ow`.`sessions` WHERE CONVERT(`SessionName` USING utf8) LIKE '%:SessionName1%'";
  </code></pre>
  
  <p>Here is the PHP code processing the query; </p>
  
  <pre><code>//bind params
                  $SessionName1 = filter_input(INPUT_GET, 'search');
                  $stmt -&gt; bindValue(':SessionName1', $SessionName1, PDO::PARAM_STR);
  
                  //execute
                  $success = $stmt -&gt; execute();
  
                  if (!$success){
                       print $stmt-&gt;errorInfo()[2]; //PDO driver error message
                  }
  
                  else{
                  }
  
                  //array
                  $r = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
                  $dbh = null;
  
                  if(!$r)
                  {
                      echo "No Results";
                  }      
  
                  foreach ((array) $r as $row) {
                   echo $row['SessionId'];
                   echo $row['SessionName'];
                  } 
  </code></pre>
  
  <p>For some reason this will not return any results the <code>execute</code> part is working fine and passing the success test but then once it gets to the array it returns no results.</p>
  
  <p>I checked and <code>$SessionName1</code> has the term in it from search so it is being passed to the query ok.</p>
  
  <p>When I change the <code>%:SessionName1%</code> to <code>football</code> which is the search term I am testing with, the code returns the results fine but once changed back to <code>:SessionName1</code> it will not return the results even though the search term is exactly the same.</p>
  
  <p>Can anybody see what I am doing wrong, I spent ages looking at this and cannot see the error.</p>
  
  <p>I have searched everywhere for an answer to this but I couldn't find one specific to this issue, also I am a beginner with PHP and SQL.      </p>