title: Could you help me understand this PHP code with a PDO query?
body: <p>Good colleagues, I am learning PHP a little more thoroughly since I am a bit newbie, I already did database queries with MySQLi and I want to learn the PDO alternative since I can connect to other databases other than MySQL.
  So I decided to see different examples and I found one that I did not understand well so I decided to see line by line.</p>
  <pre><code>&lt;?php
      function doSomething($id){
          
          $pdo= conecta(); 
          $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $motivo= &quot;probar&quot;; 
          $res=0;
          $e=&quot;&quot;;
  
          try{
              $pdo-&gt;beginTransaction();
  
              $sql= &quot;INSERT INTO registro (nombre_c, desc_c, motivo_c) (SELECT nombre_a, desc_a, :motivo FROM autos WHERE id=:id)&quot;;
              $stmt= $pdo-&gt;prepare($sql);
              $stmt-&gt;bindParam(':id', $id, PDO::PARAM_INT);
              $stmt-&gt;bindParam(':motivo', $motivo,PDO::PARAM_STR);
              $res1 = $stmt-&gt;execute();
              
              $sql=&quot;DELETE FROM autos WHERE id=:id&quot;;
              $stmt= $pdo-&gt;prepare($sql);
              $stmt-&gt;bindParam(':id', $id, PDO::PARAM_INT);
              $res2 = $stmt-&gt;execute();
  
              $pdo-&gt;commit();
              $res=$res1&amp;&amp;$res2;
          }catch(PDOException $e){
              $pdo-&gt;rollBack();
          }
  
          unset($stmt);
          unset($pdo);
          return array($res?&quot;actualizado&quot;:&quot;error&quot;, $e);
  
      }
  
  ?&gt;
  
  </code></pre>
  <p>My idea is to understand it line by line so that what I learned is better for me.
  And from what I see a Method is created that receives the $ id property and connects to a database and an update is created (of which I do not know if the query is well done because it seems strange to me)
  I am having a hard time understanding PDO queries, so I wanted to see what tips or advice you could give me.</p>
  <p><strong>My query is to know and decipher what exactly does the function since it confuses me a lot</strong></p>