title: PDO prepared statements for INSERT and ON DUPLICATE KEY UPDATE with named placeholders
body: <p>I'd like to switch PDO INSERT and UPDATE prepared statements to INSERT and ON DUPLICATE KEY UPDATE since I think it'll be a lot more efficient than what I'm currently doing, but I'm having trouble figuring out the correct syntax to use with named placeholders and bindParam.</p>
  
  <p>I found several similar question on SO, but I'm new to PDO and couldn't successfully adapt the code for my criteria. This is what I've tried, but it doesn't work (it doesn't insert or update): </p>
  
  <pre><code>try { 
    $stmt = $conn-&gt;prepare('INSERT INTO customer_info (user_id, fname, lname) VALUES(:user_id, :fname, :lname)'          
   'ON DUPLICATE KEY UPDATE customer_info SET fname= :fname, 
                                              lname= :lname   
                                              WHERE user_id = :user_id'); 
    $stmt-&gt;bindParam(':user_id', $user_id);  
    $stmt-&gt;bindParam(':fname', $_POST['fname'], PDO::PARAM_STR);
    $stmt-&gt;bindParam(':lname', $_POST['lname'], PDO::PARAM_STR);      
    $stmt-&gt;execute();
  }
  </code></pre>
  
  <p>This is a simplified version of my code (I have several queries, and each query has between 20 - 50 fields).  I'm currently updating first and checking if the number of rows updated is greater than 0 and if not then running the Insert, and each of those queries has it's own set of bindParam statements.</p>