title: How to bind multiple values using PDO prepared statements?
body: <p>Here is my code</p>
  <pre><code>$bindParams = [
  'name1'  =&gt; 'Law',
  'name2'  =&gt; 'King'
                ];
  
  $sql = &quot;INSERT INTO users (name) VALUES (:name1),(:name2);&quot;;
  
  $db-&gt;prepared_query($sql,$bindParams);
  
  
  
  class Database
  {
  public function __construct
  (
      public \PDO $PDO
  )
  {}
  
  public function prepared_query(string $sql='',$bindParams=[]): bool
  {
      $stmt = $this-&gt;PDO-&gt;prepare($sql);
  
      if(count(value:$bindParams) !=0)
      {
          foreach ($bindParams as $k =&gt; $v)
          {
              $stmt-&gt;bindParam(param:&quot;:$k&quot;,var:$v);
          }
      }
      $x = $stmt-&gt;execute();
  
      if($x)
      {
          return true;
      }else{
               return false;
           }
      }
  }
  </code></pre>
  <p>The problem I am facing is that in the foreach loop the second value from array $bindParams having key name2 and value king is overriding $stmt-&gt;bindParam and only name2 king is inserted in the database. And for every insert I am getting king in database. Here is screen shot of database. How can I insert both records from array sucessfully without repetition.</p>
  <p><a href="https://i.stack.imgur.com/lTQ0V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lTQ0V.png" alt="enter image description here" /></a></p>