title: Save in mysql from foreach
body: <p>Hi friends sorry for my english. I have question how can I save links into mysql ?? I'm newbie in programming php. Thanks for all answer.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  set_time_limit(0); 
  $db = new mysqli('localhost', 'root', 'pass');
  $db -&gt; query("SET CHARSET utf8");
  $db -&gt; query("SET NAMES 'UTF-8' COLLATE 'utf8_polish_ci'");
  
  $html = file_get_contents("http://www.somesite.com");
  $dom = new DOMDocument();
  $dom-&gt;loadHTML($html);
  
  $divs = $dom-&gt;getElementsByTagName('div');
  foreach ($divs as $div){
       if(preg_match('/\bimgw\b/', $div-&gt;getAttribute('class'))) {
           $links = $div-&gt;getElementsByTagName('a');
           foreach($links as $link){
                $li = $link-&gt;getAttribute('href');
                  $zapytanie = "SELECT * FROM `dane` WHERE link='".$li."';";
                  $wynik = $db-&gt;query($zapytanie);
                  $baza = mysql_fetch_assoc($wynik) ;
                  if ($baza['link'] == $li)
          print ("OK Exist ".$baza['ID'].'&lt;br&gt;');
                  else
  
                  echo ("&lt;br&gt;Not exist ".$baza['ID']);
  
           }
       }
  }
  
  ?&gt;
  </code></pre>