title: Update many rows in one table (long execution time)
body: <p>I have one table (cp_article) with arround 63k rows with 4 columns (cp_articleID, cp_articleNR, cp_articleNAME, cp_articleDRAWING) and I want to update cp_articleDRAWING with $i WHERE cp_articleNR = $NR</p>
  <p>Before I read from DB all cp_articleNR and put in an array to count it and use it in my for loop.
  This is at the moment just for testing, later I want to put a patch to a PDF file in cp_articleDRAWING but the performance is really bad. Below you can find my code, the first function is for getting all cp_articleNR and the second function is to update the cp_articleDRAWING with a rising number where cp_articleNR = $NR from an array</p>
  <p>In 120 seconds I can update around 1700-2100 rows, on my dev-server around 3000 rows. My personal feeling is that is too slow.</p>
  <pre><code>//Get all articleNR from DB and put in Array
  function getArticleFromDB()
  {
      try {
          require '../includes/dbh.php';
          $sql = &quot;SELECT cp_articleNR FROM cp_article&quot;;
          $ergebnis = $db_link-&gt;query($sql);
          $array = array();
          while ($row = mysqli_fetch_assoc($ergebnis)) {
              $array[] = $row;
          }
          //Export to array
          return $array;
      } catch (Exception $ex) {
          echo &quot;Fehler: &quot; . $ex-&gt;getMessage();
      }
  }
  
  
  function updateDrawingPath()
  {
      //Datenbankverbindung
      require '../includes/dbh.php';
      //Schreibe Artikel in Array
      $array = getArticleFromDB();
      //Count all entrys in Array
      $count = count($array);
      //
      $stmt = $db_link-&gt;prepare(&quot;UPDATE cp_article SET cp_articleDRAWING = ? WHERE cp_articleNR = ?&quot;);
      $stmt-&gt;bind_param(&quot;ii&quot;, $i, $nr);
      //Execute loop until $count is reached
      for ($i=0; $i &lt; $count; $i++) {
          $i = $i;
          $nr = $array[$i][&quot;cp_articleNR&quot;];
          $stmt-&gt;execute();
      }
      $stmt-&gt;close();
      $db_link-&gt;close();
  }
  
  //execute function
  updateDrawingPath();
  </code></pre>