title: SQL Select statement on cvs file in php
body: <p>I am trying to do some sql querying on cvs file in php. I found this</p>
  
  <p><a href="https://stackoverflow.com/questions/937912/writing-a-php-file-to-read-from-csv-and-execute-sql-query">Writing a PHP file to read from CSV and execute SQL Query</a></p>
  
  <p>but I was unable to change it for the SELECT statement</p>
  
  <p>my attempt: </p>
  
  <pre><code>&lt;?php
  $fin = fopen('./file.csv','r') or die('cant open file');
  $conn = mysql_connect('localhost', 'name', 'pw');
  If (!$conn) {
      die ('Could not connect: ' . mysql_error());
  }
  @mysql_select_db('name') or die ('Unable to select database');
  mysql_query("SET NAMES 'utf8'", $conn);
  mysql_query("SET CHARACTER SET 'utf8'", $conn);
  
  echo "Connection succeeded &lt;br /&gt;\n";
  
  while (($data=fgetcsv($fin,1000,","))!==FALSE) {
      $query = "SELECT * FROM file";
      $result = mysql_query($query);
  
      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        print_r($row);
      }
  
      }
  fclose($fin);
  mysql_close();
  ?&gt;
  </code></pre>
  
  <p>lets say I have an <em>file.csv</em> and I want to execute something like this: <code>Select col1,col2 from file.cv where c3='whatever'</code></p>
  
  <p>OR is there some other, more elegant way how to querying cvs in php?</p>
  
  <p>Thank you!</p>