title: How to insert scraping data to mysql
body: <p>i am fetching data from other websites can any one tell me how to insert fetch data to mysql database</p>
  
  <p>Below code i am using to fetch results coming</p>
  
  <pre><code>require_once('config.php');
      //Connect to mysql server
  $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  if(!$link) {
      die('Failed to connect to server: ' . mysql_error());
  }
  
  //Select database
  $db = mysql_select_db(DB_DATABASE);
  if(!$db) {
      die("Unable to select database");
  }
  
  $urls = $_POST["urls"];
  require_once('simple_html_dom.php');
  $useragent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
  
  foreach ($urls as $url) 
  {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
      curl_setopt($curl, CURLOPT_USERAGENT, $useragent); 
      $str = curl_exec($curl);
      curl_close($curl);
  
      $html= str_get_html($str);
      foreach($html-&gt;find('span.price') as $e)
          echo  $e-&gt;innertext . '&lt;br&gt;';
  }
  
  //Create INSERT query
  $qry = "INSERT INTO scrapdata(price) VALUES('$e')";
  $result = @mysql_query($qry);
  
  //Check whether the query was successful or not
  if($result) {
      echo ("Added Success");
  }else {
      echo ("Not Added");
  }
  </code></pre>