title: How to insert array data into mysql db from instagram api response using php?
body: <p>I am calling instagram api and getting a response as an array inside $record.</p>
  
  <p>I wonder how I can get username, first_name, profile_picture, id, last_name variables from $record and insert them into mysql db if they are not already in mysql db? Could any one show me how this can be done? Thanks in advance.</p>
  
  <p>According to <a href="http://instagram.com/developer/endpoints/relationships/#get_users_follows" rel="nofollow" title="Instagram API Docs">Instagram API Docs</a> the following api:</p>
  
  <pre><code>https://api.instagram.com/v1/users/XXXX/follows?access_token==XXXX&amp;count=-1 
  </code></pre>
  
  <p>edited : Now i can print the array variables but how to insert them into mysql db and avoid duplication?</p>
  
  <pre><code>foreach($record-&gt;data as $user) // each user data (JSON array) defined as $user
  {
  echo "User Name:".$user-&gt;username;
  echo "&lt;br&gt;Bio:".$user-&gt;bio;
  echo "&lt;br&gt;Website:".$user-&gt;website;
  echo "&lt;br&gt;Profile Picture:".$user-&gt;profile_picture;
  echo "&lt;br&gt;Full Name:".$user-&gt;full_name;
  echo "&lt;br&gt;id:".$user-&gt;id;
  echo "&lt;br&gt;&lt;br&gt;";
  }
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>{
      "data": [{
          "username": "washington",
          "first_name": "George",
          "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_6623_75sq.jpg",
          "id": "1",
          "last_name": "Washington"
      },
      {
          "username": "SammyDavis",
          "first_name": "Sammy",
          "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",
          "id": "29648",
          "last_name": "Davis"
      },
      {
          "username": "FrankTheTank",
          "first_name": "Frank",
          "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",
          "id": "13096",
          "last_name": "Roberts"
      }]
  }
  </code></pre>
  
  <p>php script:</p>
  
  <pre><code>$url = "https://api.instagram.com/v1/users/XXXX/follows?access_token==XXXX&amp;count=-1";
  $api_response = get_data(''.$url);
  $record = json_decode($api_response); // JSON decode 
  
  //now i want to get username,first_name,profile_picture,id,last_name variables and insert it into mysql db
  
  
  /* gets the data from a URL */
  function get_data($url) {
      $ch = curl_init();
      $timeout = 5;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
  }
  </code></pre>