title: Update a row if exists, if not create a new one MySQL
body: <p>I am inserting a name, number, and company into a DB. </p>
  
  <p>My table is simply:</p>
  
  <pre><code>id(primary key)
  name
  slideView
  company
  </code></pre>
  
  <p>I need to update this information if a name passed to it exists, if not create a new row with this data. I have looked at <code>REPLACE INTO</code> but I dont think that will work for me... as I dont touch the ID at all.</p>
  
  <p>My code is:</p>
  
  <pre><code>insertData($name,$count,$company);
  
  function insertData($name, $count, $company) {
  
      #Try/Catch statement to connect to DB, and insert data
      try {
          #DB username/password   
          $usernameDB = '****';
          $passwordDB = '****';
  
          #Create new PHP Database Object with the address, username, and password as parameters
          $pdo = new PDO('mysql:host=localhost;dbname=*****', $usernameDB, $passwordDB);
  
          #Set pdo attributes to handle errors 
          $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
          #assign the sth variable (sth means statement handle) to insert the data
          $sth = $pdo-&gt;prepare("REPLACE INTO ***** SET name = ?, slideView = ?, company = ?");
  
          #Execute the insert
          $sth-&gt;execute(array($name,$count,$company));
  
      #Error if can't connect or insert
      } catch(PDOException $e) {
          echo 'Error: ' . $e-&gt;getMessage();
      }#/try
  }
  </code></pre>
  
  <p>I'm new to SQL and havnt found a good way to do this yet.</p>