title: MySQL to MySQLi Query issue when joining arrays
body: <p>I'm trying to convert some MYSQL querys to MYSQLI, but I'm having an issue, below is part of the script I am having issues with, the script turn a query into csv:</p>
  
  <pre><code>$columns = (($___mysqli_tmp = mysqli_num_fields($result)) ? $___mysqli_tmp : false); 
  
  // Build a header row using the mysql field names 
  
  $rowe = mysqli_fetch_assoc($result);
  $acolumns = array_keys($rowe);
  $csvstring = '"=""' . implode('""","=""', $acolumns) . '"""';
  $header_row = $csvstring; 
  
  // Below was used for MySQL, Above was added for MySQLi
  //$header_row = '';
  //for ($i = 0; $i &lt; $columns; $i++) {
  //  $column_title = $file["csv_contain"] . stripslashes(mysql_field_name($result, $i)) . $file["csv_contain"];
  //  $column_title .= ($i &lt; $columns-1) ? $file["csv_separate"] : '';
  //  $header_row .= $column_title;
  //  } 
  $csv_file .= $header_row . $file["csv_end_row"]; // add header row to CSV file 
  
  // Build the data rows by walking through the results array one row at a time 
  $data_rows = ''; 
  while ($row = mysqli_fetch_array($result)) { 
    for ($i = 0; $i &lt; $columns; $i++) { 
      // clean up the data; strip slashes; replace double quotes with two single quotes 
      $data_rows .= $file["csv_contain"] .$file["csv_equ"] .$file["csv_contain"] .$file["csv_contain"] . preg_replace('/'.$file["csv_contain"].'/', $file["csv_contain"].$file["csv_contain"], stripslashes($row[$i])) . $file["csv_contain"] .$file["csv_contain"] .$file["csv_contain"];
      $data_rows .= ($i &lt; $columns-1) ? $file["csv_separate"] : ''; 
    } 
    $data_rows .= $this-&gt;csv_end_row; // add data row to CSV file 
  } 
  $csv_file .= $data_rows; // add the data rows to CSV file 
  
  if ($this-&gt;debugFlag) { 
    echo "Step 4 (repeats for each attachment): CSV file built. \n\n"; 
  } 
  
  // Return the completed file 
  return $csv_file; 
  </code></pre>
  
  <p>The problem I am having is when building a header row for the column titles mysqli doesn't use field_names so I am fetching the column titles by using <code>mysqli_fetch_assoc()</code> and then <code>implode()</code> the array, adding the <code>,</code>'s etc for the csv.</p>
  
  <p>This works but when I produce the csv I am deleting the first data row when the header is active, when I remove my header part of the script and leave the header as null I get all data rows and a blank header (As expected).</p>
  
  <p>So I must be missing something when joining my header to array to the <code>$csv_file</code>.</p>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p>Many Thanks</p>
  
  <p>Ben</p>