title: Why am I getting a Fatal error with this MongoDB function?
body: <p>I've got a simple php script for getting a csv file into array and inserting each row into MongoDB (CD Collection). But somehow insert returns an error after first successful one:</p>
  
  <pre><code>"Fatal error: in C:\xampp\htdocs\mongo\lesson1\index.php on line 17"
  </code></pre>
  
  <p>Here's the code. What could possibly cause such an error? DB receives only one (first).</p>
  
  <pre><code>$filename = 'd:/cd_col.csv'; // Each line: Title;No. of CD with movie
  $csvfile = fopen($filename,'rb'); 
  while(!feof($csvfile)) {
      $csvarray[] = fgetcsv($csvfile);
  }
  $m = new MongoClient();
  $db = $m-&gt;mymovies;
  $collection = $db-&gt;movies;
  $id=0;
  foreach($csvarray as $key=&gt;$value)
  {
      $movie = explode(';', $value[0]);
      $fmovie = array('_id'=&gt;++$id, 'title'=&gt;$movie[0], 'cdno'=&gt;$movie[1]);
      if($collection-&gt;save($fmovie)===true) { // this is line 17
          echo 'Successful insert: '.$key;
      }
  }
  </code></pre>