title: PHP json_encode() adding extra double-quotes around Array Elements
body: <p>I have an Array named $items that looks like the following:</p>
  
  <pre><code>array   (
              0 =&gt; '{"id":"1", "qty":"1", "price":"12.51"}',
              1 =&gt; '{"id":"2", "qty":"2", "price":"25.02"}',
          )
  </code></pre>
  
  <p>I'm trying to build a mySQL INSERT statement which includes the data in $items as follows:</p>
  
  <pre><code>$sql = 'INSERT INTO vals (id, items, timestamp) 
          VALUES (' . $id . ', "' . json_encode($items) . '", "' . date('Y-m-d H:i:s')  . '")';
  </code></pre>
  
  <p>However, the INSERT into mySQL is failing due to json_encode() adding double-quotes around the Array Elements:</p>
  
  <pre><code>INSERT INTO
              vals
                      (
                          id,
                          items,
                          timestamp
                      )
          VALUES
                      (
                          1,
                          "[
                              "{\"id\":\"1\", \"qty\":\"1\", \"price\":\"12.51\"}",
                              "{\"id\":\"2\", \"qty\":\"2\", \"price\":\"25.02\"}"
                          ]",
                          "2015-11-26 20:31:02"
                      )  
  </code></pre>
  
  <p>It's the double-quotes before/after the curly-braces "{ ...data... }" that are the problem.</p>
  
  <p>Is there a way to convert the Array to a String that will elimnate these extra quotes?</p>
  
  <p>Thanks much for any guidance!</p>
  
  <h2>EDIT:</h2>
  
  <p>From the examples below, I'm trying to use mysqli prepared statements.</p>
  
  <p>I'm executing the following:</p>
  
  <pre><code>$stmt-&gt;bind_param("i", (int) $id)
  </code></pre>
  
  <p>and am getting this error:</p>
  
  <pre><code>ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' 
  with message 'Call to a member function bind_param() on a non-object'
  </code></pre>
  
  <p>I didn't get  an error executing the following: </p>
  
  <pre><code>$stmt = $mysqli-&gt;prepare($sql)
  </code></pre>
  
  <p>so I'm thinking $stmt should be okay to call bind_param() on.</p>
  
  <p>I looked at the PHP docs and don't believe I need to do anything else with $stmt. Does anyone see something I'm missing?</p>