title: How to insert an array in to table using PDO in PHP
body: <p>I am new to PDO and need to insert simple array data to a table. <code>print_r($ID)</code> and <code>print_r($CODE)</code> are as follows respectively,</p>
  <pre><code>Array
  (
      [0] =&gt; 1
      [1] =&gt; 2
      [2] =&gt; 3
      [3] =&gt; 4
  )
  Array
  (
      [0] =&gt; 1008M
      [1] =&gt; 1039E
      [2] =&gt; 1040E
      [3] =&gt; 198M
  )
  </code></pre>
  <p><code>$ID</code> and <code>$CODE</code> are fetched through another query which has in another host.
  I need to insert following array data to a table using PDO. Here is my try.</p>
  <pre><code>&lt;?php
  
  $db = new PDO(&quot;mysql:host=localhost;dbname=testdatabase&quot;, 'root', '');
  $db -&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  $sql = &quot;INSERT INTO dummy (ID, CODE) VALUES (?,?)&quot;;
  $stmt = $db-&gt;prepare($sql);
  $stmt-&gt;execute(array($ID, $CODE));
  
  ?&gt;
  </code></pre>
  <p>But this provides me an notice on,</p>
  <pre><code>Notice: Array to string conversion in C:\xampp\htdocs\mytestdata\test1.php on line 36
  </code></pre>
  <p>and the output in the dummy table shows as follows,</p>
  <pre><code>ID CODE
  0  array
  </code></pre>
  <p>can someone show me where I have messed this code?</p>
  <p>Expected Result:</p>
  <pre><code>ID CODE
  1  1008M
  2  1039E
  3  1040E
  4  198M
  </code></pre>