title: How to convert my database ID number to text before CSV export?
body: <p>I'm hoping this is an easy one. How can I convert the ID number in mysql database into text before exporting it into a csv file?</p>
  
  <p>Here is my code that exports my data:</p>
  
  <pre><code>$con = mysqli_connect('localhost', 'user', 'password', 'database');
  
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  header('Content-Type: text/csv; charset=utf-8');
  header('Content-Disposition: attachment;filename=csv_file.csv');
  $output = fopen('php://output', 'w');
  
  $query = 'SELECT * FROM table';
  $result = mysqli_query($con, $query);
  
  while ($field = mysqli_fetch_assoc($result)){
      fputcsv($output, $field);
  }
  </code></pre>
  
  <p>I can export the data from the database into a csv just fine but is there a way to convert the ID number to text so that excel doesn't strip away the leading zeros?</p>
  
  <p>Thanks!</p>