title: Return mysqli query as comma separated values with PHP
body: <p>I have the following query that is returning:</p>
  
  <pre><code>"Code1""Code2""Code3"
  </code></pre>
  
  <p>What I need is for the result to be in CSV format like this:</p>
  
  <pre><code>'Code1','Code2','Code3'
  </code></pre>
  
  <p>How do I modify my code to accomplish this?</p>
  
  <pre><code>&lt;?php
  
  $conn = new mysqli("127.0.0.1", "user", "password", "table", "3306");
  
  if(mysqli_connect_errno($conn)) {
  echo "Unable to connect to database server";
  }  
  
  $result = mysqli_query($conn,"SELECT code FROM sourcecodes");
  while($row = $result-&gt;fetch_assoc()) {
      $mydata = ($row['code']);
      echo json_encode($mydata);
  }
  
  $result-&gt;free();
  $conn-&gt;close();
  ?&gt;
  </code></pre>