title: Parsing JSON to MySQL table
body: <p>I'm using Zend Framework (1.12) and I'd like to create a table based on a JSON file. I've already created the table and its fields (they're all longtext for now), all it has to do is insert them into the right columns. I followed these examples:</p>
  
  <p><a href="http://www.daniweb.com/web-development/php/threads/381669/json-to-mysql-with-php" rel="nofollow noreferrer">http://www.daniweb.com/web-development/php/threads/381669/json-to-mysql-with-php</a> (second post)
  <a href="https://stackoverflow.com/questions/11257694/parse-json-to-mysql">Parse JSON to mySQL</a></p>
  
  <p>The problem is that my JSON is constructed differently (mine has a "root element" called Actie, don't really know the right term) which contains an array with all the objects. Currently, I'm using this code:</p>
  
  <pre><code>$actieurl = "http://creative3s.com/thomas/nmdad/actie.json";
          $my_arr = json_decode(file_get_contents($actieurl));
  
          $db = new Zend_Db_Adapter_Pdo_Mysql(array(
              'host' =&gt; 'localhost',
              'username' =&gt; 'root',
              'password' =&gt; NULL,
              'dbname' =&gt; 'zf-tutorial'
              ));
  
          foreach($my_arr as $key =&gt; $value){
              $sql[] = (is_numeric($value)) ? "`$key` = $value" : "`$key` = '" . mysql_real_escape_string($value) . "'"; 
          }
  
          $sqlclause = implode(",",$sql);
          $query = "INSERT INTO `testerdetest` SET $sqlclause";
          $db-&gt;query($query);
  </code></pre>
  
  <p>But I'm getting an error saying that I'm passing an array:</p>
  
  <pre><code>Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\Users\Thomas\Documents\GitHub\NMDAD-testing\application\controllers\IndexController.php on line 29
  </code></pre>
  
  <p>Does anyone know how to solve this with a JSON of this format? Keep in mind that I cannot alter the JSON in any way. Extra links:</p>
  
  <p>JSON: <a href="http://creative3s.com/thomas/nmdad/actie.json" rel="nofollow noreferrer">http://creative3s.com/thomas/nmdad/actie.json</a>
  Table structure: <a href="https://i.imgur.com/KtXeEuw.png" rel="nofollow noreferrer">http://i.imgur.com/KtXeEuw.png</a></p>