title: How to escape single-quote (apostrophe) in string using php
body: <p>I have a SQL query like this:-</p>
  
  <pre><code>$stmt = $pdo-&gt;prepare(
     "SELECT * FROM `products_keywords` WHERE `product_type` = '" . $product_type . "' ");
  </code></pre>
  
  <p>I don't know what will be the value in the <strong>$product_type</strong> variable. But Now, I am getting <strong>Men's Shirt</strong> in <strong>$product_type</strong> variable which is causing the syntax error in my SQL query. I am sure this error is due to the single quote in <strong>Men's Shirt</strong> value. How I escape this value according to my query? And how to check if there is <strong>single quote</strong> in my <strong>$product_type</strong> variable and then escape it according to my query. Thanks in advance.  </p>