Jump to content
php.lv forumi

Kaa izeksporteet datu baazi no mysql ar UTF-8 formatingu uz xls vai cs


mrchinaski

Recommended Posts

Man ir datu baaze ar UTF-8 encodingu, tachu, kad eksporteeju kaa csv un atveru peec tam ekselii - nobruuk visi latvieshu burti, luuk skripts, ko izmantoju:

 

<?php
$host = 'localhost';
$user = 'xxxxxxxxx';
$pass = 'xxxxxxxxx';
$db = 'xxxxxxx';
$table = 'xxxxxx';
$file = 'export';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";

$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>

 

Kaads varbuut var ieteikt, kaa to dariit taa, lai pareizi raadiitos lv simboli/burti.

 

Paldies!

Link to comment
Share on other sites

Paldeis par aatro atbildi, tik es esmu galiigs iesaaceejs php... kur man iisti likt sho kveeriju? Meegjinaaju shaadi, bet joprojaam nekas:

 

mysql_query("SET NAMES UTF8" , "$link");
$result = mysql_query("SHOW COLUMNS FROM ".$table."");

 

 

Paldies!

Edited by mrchinaski
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...