title: Write to .csv file with PHP (Commas in Data Error)
body: <p>I am working on a PHP statement that runs a query and then writes the data to a .csv file. The problem I am having is that some of the data I am receiving from the server has commas in the data which causes for the .csv file to enter data in the wrong place. Below I have an example of the code.</p>
  
  <pre><code>$sql = "Select *
  From table;"
  
  $data = mysqli_query($link, $sql);
  $row= ("Column One, Column Two, Column Three\n");
  
  while ($result = $data-&gt;fetch_assoc()) {
      $row .= ("$result[columnOne], $result[columnTwo], $result[columnThree]\n");
  }
  
  $fd = fopen("./filePath.csv", "w") or die ("Error Message");
  fwrite($fd, $row);
  fclose($fd);
  </code></pre>
  
  <p>Column three is where the data contains commas which causes for it to write to different cells in the .csv file. Is there any solution to make the $result[columnThree] data stay in one cell even though it contains commas in it?</p>