October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Export MySQL to Excel or CSV with Arabic Text Displayed Correctly

When Arabic in a MySQL CSV export looks correct in Notepad but garbled in Excel, check each encoding layer and import the file as UTF-8.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If Arabic appears correctly in Notepad but turns into garbled characters when a MySQL CSV export is opened in Excel, the likely problem is how the spreadsheet reads the file—not necessarily the stored Arabic text. Check the character encoding from the database through PHP, then make sure Excel imports the CSV as UTF-8. The 2012 SitePoint thread describes this symptom but does not establish which fix worked for its original poster.

Why Arabic can look right in Notepad but wrong in Excel

A CSV file is plain text: it contains bytes and separators, but it does not reliably tell every program how those bytes should be interpreted. If the database stores Arabic correctly and PHP writes the intended UTF-8 bytes, a text editor that recognizes UTF-8 may display them properly while a spreadsheet application guesses a different encoding. That mismatch produces mojibake—readable-looking but incorrect characters.

As an Amazon Associate I earn from qualifying purchases.

A correct database column charset alone does not prove the entire export is correct. Check each stage independently:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Stored text: Confirm the value retrieved from MySQL is Arabic, not already corrupted.
  • Column and table character sets: Verify the schema supports the encoding used for the text.
  • Database connection: Configure the connection to communicate in the intended character set.
  • PHP output: Ensure the response and written file bytes use UTF-8 consistently.
  • CSV structure: Quote and delimit fields correctly; CSV escaping is separate from text encoding.
  • Excel import: Choose or detect UTF-8 when opening the file.

The SitePoint poster’s example already used SET NAMES 'utf8' and said the CSV’s Arabic was readable in Notepad. That does not prove every layer was configured correctly, but it means the thread cannot establish that a missing SQL charset setting was the sole cause.

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

Try importing the file as UTF-8 in Excel

In the January 2012 discussion, forum participants recommended using Excel’s text-import workflow, selecting UTF-8 (code page 65001) and a comma delimiter. This is dated forum advice, not a guarantee for every Excel release or operating system; the thread names no version and reports no confirmed fix. If your Excel version offers an import option, explicitly select UTF-8 rather than relying on a double-click to infer the encoding.

Importing is especially practical when you control how the recipient opens the file. If the file must be opened directly by recipients who may not know how to choose an encoding, a UTF-8 byte-order mark (BOM) is sometimes considered to help applications identify UTF-8. The SitePoint thread suggested trying one, but its code contains a byte-sequence discrepancy, and the discussion does not confirm a successful result. Do not copy its BOM snippet as-is; verify any implementation against reliable encoding documentation and the spreadsheet versions your recipients use.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

Generate the export with current PHP APIs

The forum example uses the old mysql_* PHP functions. PHP deprecated the original MySQL extension in PHP 5.5.0 and removed it in PHP 7.0.0; current code should use MySQLi or PDO_MySQL instead. PHP’s manual also identifies a dedicated connection character-set API as preferable to issuing SET NAMES through a query. See the PHP manual’s charset guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For CSV rows, use PHP’s fputcsv() rather than assembling comma-separated lines by hand. It handles CSV field quoting, but it does not by itself ensure that Excel will recognize the file’s byte encoding. PHP’s manual notes that relying on the default escape argument is deprecated as of PHP 8.4.0; pass the argument explicitly. For example, the final argument below is an empty string to disable PHP’s proprietary escape behavior:

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
<?php
// Configure the database connection for UTF-8 using your chosen API.
// Example with MySQLi:
$mysqli = new mysqli($host, $user, $password, $database);
$mysqli->set_charset('utf8mb4');

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="export.csv"');

$out = fopen('php://output', 'w');
while ($row = $result->fetch_assoc()) {
    fputcsv($out, $row, ',', '"', '');
}
fclose($out);
?>

This is a pattern, not a complete application: create and execute the query, handle connection and query errors, and select fields in the order you want exported. Choose a connection charset appropriate to your schema and data; utf8mb4 is commonly used for modern MySQL Unicode data. The response header labels the response as UTF-8, while the connection setting governs how character data is exchanged with MySQL. Neither setting dictates how a particular Excel version will detect a downloaded CSV.

The PHP fputcsv() manual documents the function and its version-sensitive escape argument. CSV quoting and encoding solve different problems: a correctly quoted Arabic field can still be decoded with the wrong character set.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Validate where the encoding changes

  1. Check the retrieved value. Inspect the Arabic text returned by the database before generating the file. If it is already garbled, investigate stored data, schema charset, and the connection before changing Excel settings.
  2. Check the downloaded file. Inspect the file’s encoding or bytes with a tool that can identify UTF-8. Do not infer correctness only from the response header: the actual output bytes matter.
  3. Check the connection charset. Confirm the MySQLi or PDO connection uses the intended character set and that the schema and stored values are compatible.
  4. Test Excel’s import path. Import the CSV as UTF-8 and select comma as the delimiter where those options are available. Compare the result with a known-good UTF-8 text file containing the same Arabic sample.
  5. Separate encoding from CSV formatting. If columns split incorrectly or quotation marks are misplaced, fix field generation separately from character decoding.

If the database value is correct and the downloaded bytes are valid UTF-8, but Excel still shows mojibake, focus on that Excel version’s import or detection behavior. If the bytes are not valid UTF-8, fix the export or connection before trying an Excel workaround.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.