title: how I make a single query for both insert and update?
body: <p>Suppose we have a mysql table something like this </p>
  
  <p><code>id, userid, days, start, and close</code></p>
  
  <p>and we have data for each columns like this - </p>
  
  <pre><code>1, 3, mon, 01.00, 02.00,
  2, 3, tue, 03.00, 05.00,
  3, 3, wed, 04.00, 06.00,
  4, 3, thu, 05.00, 07.00,
  5, 3, fri, 06.00, 08.00,
  6, 3, sat, 07.00, 10.00,
  7, 3, sun, 08.00, 12.00,
  </code></pre>
  
  <p>with this data, I need to update or insert my table. (if userid is not exist in table it should be insert or if userid exist in db it should be update.)</p>
  
  <p>Can I know, is there a way to make a mysql single query for this? I tried it with <code>INSERT ... ON DUPLICATE KEY UPDATE</code> there I can only edit single row that mean I can not insert or update table with multiple rows using <code>INSERT ... ON DUPLICATE KEY UPDATE</code>. </p>
  
  <p>At the moment I have used 2 different queries for inset and update </p>
  
  <p>This is my insert query -</p>
  
  <pre><code>$q = "INSERT INTO availability (userid, days, opentime, closetime) 
          VALUES (?, 'Monday', ?, ?),
                   (?, 'Tuesday', ?, ?),
                   (?, 'Wednesday', ?, ?),
                   (?, 'Thursday', ?, ?),
                   (?, 'Friday', ?, ?),       
                   (?, 'Saturday', ?, ?),                         
                   (?, 'Sunday', ?, ?)";                          
              $stmt = mysqli_prepare($dbc, $q);
              mysqli_stmt_bind_param($stmt, 'issississississississ', 
                                              $userId, $monOpen, $monClose, 
                                              $userId, $tueOpen, $tueClose,
                                              $userId, $wedOpen, $wedClose,
                                              $userId, $thuOpen, $thuClose,
                                              $userId, $friOpen, $friClose,
                                              $userId, $satOpen, $satClose,
                                              $userId, $sunOpen, $sunClose);                          
              // Execute the query:
              mysqli_stmt_execute($stmt);
  </code></pre>