bradgrafelman;10994233 wrote:What is the name of the collation used on the columns in the table?
Also, can you show us how you connect to the DB and execute the query? It could be that you need to first execute a SET NAMES command to set the connection collation/character set; see the MySQL manual page 9.1.4. Connection Character Sets and Collations for more info.
Hello,
Database table fields are uft8, It did not work both as excel and csv
It is opening Fine in Notepad, but not in excell
Thats the complete Code:
<?php
header( 'Content-Type: text/csv; charset=utf-8; encoding=UTF-8' );
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header( 'Content-Disposition: attachment;filename=export.csv' );
$conn = mysql_connect( 'localhost', 'root', '' ) or die( mysql_error( ) );
mysql_select_db( 'labora_donnation', $conn ) or die( mysql_error( $conn ) );
mysql_query("SET NAMES 'utf8'");
$query = sprintf( 'SELECT * FROM pr2' );
$result = mysql_query( $query, $conn ) or die( mysql_error( $conn ) );
$row = mysql_fetch_assoc( $result );
if ( $row )
{
echocsv( array_keys( $row ) );
}
while ( $row )
{
echocsv( $row );
$row = mysql_fetch_assoc( $result );
}
function echocsv( $fields )
{
$separator = '';
foreach ( $fields as $field )
{
if ( preg_match( '/\\r|\\n|,|"/', $field ) )
{
$field = '"' . str_replace( '"', '""', $field ) . '"';
}
echo $separator . $field;
$separator = ',';
}
echo "\r\n";
}
?>
when it open the file with
Notepad:
id,name,company,numyear,skill,lang,doc,location,subid,date1,date2,conf,oldnew,fil,selek,shahadat,typx,genderprefer
1,CONT22,aaaaa,6,gfhghgg, Arabic English French ,hgfhgfh,0,0,2011-09-01,2011-09-30,yes,new,,إداري,,إتصل بنا,
2,hgjjhjh11,gfdgfgfgg12,22,jhjhj, Arabic English French ,doc11,0,0,2011-10-19,2011-10-20,yes,new,,إداري,,التسجيل للدورة التدريبية,
With Excell
id name company numyear skill lang doc location subid date1 date2 conf oldnew fil selek shahadat typx genderprefer
1 CONT22 aaaaa 6 gfhghgg Arabic English French hgfhgfh 0 0 9/1/2011 9/30/2011 yes new إداري إتصل بنا
2 hgjjhjh11 gfdgfgfgg12 22 jhjhj Arabic English French doc11 0 0 10/19/2011 10/20/2011 yes new إداري التسجيل للدورة التدريبية