{"id":567,"date":"2015-05-01T09:35:37","date_gmt":"2015-05-01T09:35:37","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=567"},"modified":"2025-10-08T10:00:49","modified_gmt":"2025-10-08T10:00:49","slug":"export-data-to-excel-in-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/","title":{"rendered":"Export MySQL Data to Excel using PHP 8"},"content":{"rendered":"<p><b>Export data<\/b> feature is very useful where the data is saved on the local drive for offline uses. Export data to file functionality provides a user-friendly way to maintain a large number of data in the web application. There are various file formats are available to export data and download it as a file. Microsoft Excel is a widely used spreadsheet format that organizes and maintains data.<\/p>\n<p>Generally, export data functionality is used in the data management section of the web application. Excel is the best format to export data in a file and you can easily <b>export data to excel using PHP<\/b>. In this tutorial, we will show you how to export data to Excel in PHP.<\/p>\n<p>The example PHP 8 export Excel script lets you integrate export data to excel functionality. With one click, the user can export data from the MySQL database to Excel and download it in MS Excel file format (.xls\/.xlsx).<\/p>\n<h2>Export Data to Excel with PHP<\/h2>\n<p>In this example script, we will export data from the array (defined in the script) to an excel file.<\/p>\n<p>The <code>$data<\/code> variable holds the data in array format which will be exported to Excel using PHP:<\/p>\n<pre><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array( <br \/>&nbsp;&nbsp;&nbsp;&nbsp;array(<\/span><span style=\"color: #DD0000\">\"NAME\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"John&nbsp;Doe\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"EMAIL\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"john.doe@gmail.com\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"GENDER\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Male\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"COUNTRY\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"United&nbsp;States\"<\/span><span style=\"color: #007700\">), <br \/>&nbsp;&nbsp;&nbsp;&nbsp;array(<\/span><span style=\"color: #DD0000\">\"NAME\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Gary&nbsp;Riley\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"EMAIL\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"gary@hotmail.com\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"GENDER\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Male\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"COUNTRY\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"United&nbsp;Kingdom\"<\/span><span style=\"color: #007700\">), <br \/>&nbsp;&nbsp;&nbsp;&nbsp;array(<\/span><span style=\"color: #DD0000\">\"NAME\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Edward&nbsp;Siu\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"EMAIL\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"siu.edward@gmail.com\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"GENDER\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Male\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"COUNTRY\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Switzerland\"<\/span><span style=\"color: #007700\">), <br \/>&nbsp;&nbsp;&nbsp;&nbsp;array(<\/span><span style=\"color: #DD0000\">\"NAME\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Betty&nbsp;Simons\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"EMAIL\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"simons@example.com\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"GENDER\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Female\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"COUNTRY\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Australia\"<\/span><span style=\"color: #007700\">), <br \/>&nbsp;&nbsp;&nbsp;&nbsp;array(<\/span><span style=\"color: #DD0000\">\"NAME\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Frances&nbsp;Lieberman\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"EMAIL\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"lieberman@gmail.com\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"GENDER\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"Female\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"COUNTRY\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">\"United&nbsp;Kingdom\"<\/span><span style=\"color: #007700\">) <br \/>);<\/span><\/pre>\n<p>The <code>filterData()<\/code> function is used to filter string before added to the excel sheet row:<\/p>\n<pre><span style=\"color: #007700\">function&nbsp;<\/span><span style=\"color: #0000BB\">filterData<\/span><span style=\"color: #007700\">(&amp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">preg_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\/\\t\/\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"\\\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">preg_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\/\\r?\\n\/\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"\\\\n\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">strstr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">))&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'\"'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">str_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'\"\"'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">; <br \/>}<\/span><\/pre>\n<p>The following code helps to export data in excel and download it as a file using PHP.<\/p>\n<ul>\n<li>The <code>$fileName<\/code> variable defines the name of the excel file.<\/li>\n<li>The <b>Content-Disposition<\/b> and <b>Content-Type<\/b> headers force the excel file to download.<\/li>\n<li>Run the loop through each key\/value pair in the <code>$data<\/code> array.<\/li>\n<li>Display column names as the first row using the <code>$flag<\/code> variable.<\/li>\n<li>The <b>PHP array_walk()<\/b> function is used to filter the data together with <code>filterData()<\/code> function.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Excel&nbsp;file&nbsp;name&nbsp;for&nbsp;download <br \/><\/span><span style=\"color: #0000BB\">$filename&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"data_export_\"&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">date<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Ymd_His'<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">\".xls\"<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Headers&nbsp;for&nbsp;download <br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Content-Disposition:&nbsp;attachment;&nbsp;filename=\\\"<\/span><span style=\"color: #0000BB\">$filename<\/span><span style=\"color: #DD0000\">\\\"\"<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Content-Type:&nbsp;application\/vnd.ms-excel\"<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #0000BB\">$flag&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">false<\/span><span style=\"color: #007700\">; <br \/>foreach(<\/span><span style=\"color: #0000BB\">$data&nbsp;<\/span><span style=\"color: #007700\">as&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(!<\/span><span style=\"color: #0000BB\">$flag<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;display&nbsp;column&nbsp;names&nbsp;as&nbsp;first&nbsp;row <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">implode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">array_keys<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">))&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">\"\\n\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$flag&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">true<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;filter&nbsp;data <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">array_walk<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'filterData'<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">implode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">array_values<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">))&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">\"\\n\"<\/span><span style=\"color: #007700\">; <br \/>} <br \/> <br \/>exit;<\/span><\/pre>\n<h2>Export Data from Database to Excel (.xls) with PHP and MySQL<\/h2>\n<p>In this example script, we will export data from the MySQL database to an excel file using PHP. <\/p>\n<p><b>Create Database Table:<\/b><br \/>\nFor this example, we will create a <code>members<\/code> table in the MySQL database from which data will be exported to Excel.<\/p>\n<p>Here is the SQL statement to create a new MySQL table named members with the specified fields:<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">TABLE<\/span> members (\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">id<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">INT<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">UNSIGNED<\/span> AUTO_INCREMENT PRIMARY <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span>,\r\n    first_name <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">VARCHAR<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n    last_name <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">VARCHAR<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n    email <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">VARCHAR<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">100<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">UNIQUE<\/span>,\r\n    gender ENUM(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Male'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Female'<\/span>, <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Other'<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n    country <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">VARCHAR<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n    created DATETIME <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CURRENT_TIMESTAMP<\/span>,\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">status<\/span> TINYINT(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">1<\/span>\r\n) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"font-weight: 700;\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CHARSET<\/span>=utf8mb4;<\/pre>\n<p>Field Details:<\/p>\n<ul>\n<li>id: Integer, primary key, auto-incremented for unique user identification.<\/li>\n<li>first_name \/ last_name: Variable-length strings up to 50 characters.<\/li>\n<li>email: Variable-length string (max 100 chars), must be unique.<\/li>\n<li>gender: Enum field restricted to &#8216;Male&#8217;, &#8216;Female&#8217;, or &#8216;Other&#8217; for controlled input.<\/li>\n<li>country: Variable-length string, stores user&#8217;s country.<\/li>\n<li>created: Date and time of record creation, defaults to the current timestamp.<\/li>\n<li>status: Boolean-style field (1 = Active, 0 = Inactive), with a default of 1 for active users.<\/li>\n<\/ul>\n<p><b>Database Configuration (dbConfig.php):<\/b><br \/>\nCreate a new file named <code>dbConfig.php<\/code> to store the database connection configuration.<\/p>\n<ul>\n<li>Specify the database host (<code>DB_HOST<\/code>), username (<code>DB_USER<\/code>), password (<code>DB_PASS<\/code>), and name (<code>DB_NAME<\/code>) as per your database credentials.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Database&nbsp;configuration&nbsp;-&nbsp;update&nbsp;these&nbsp;values&nbsp;to&nbsp;match&nbsp;your&nbsp;environment <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_HOST'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'localhost'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_USER'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'root'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_PASS'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'root'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_NAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'codexworld_db'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;a&nbsp;new&nbsp;mysqli&nbsp;connection <br \/><\/span><span style=\"color: #0000BB\">$conn&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">mysqli<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">DB_HOST<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_USER<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_PASS<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_NAME<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;connection <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;In&nbsp;production,&nbsp;avoid&nbsp;echoing&nbsp;raw&nbsp;errors.&nbsp;Log&nbsp;them&nbsp;instead. <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">die(<\/span><span style=\"color: #DD0000\">'Database&nbsp;connection&nbsp;failed:&nbsp;'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">); <br \/>} <br \/> <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p><b>Export Data from Database:<\/b><br \/>\nCreate a new file named <code>index.php<\/code> to export data from the MySQL database and download it as an excel file using PHP.<\/p>\n<ul>\n<li>The <code>filterData()<\/code> function is used to filter string before added to the excel data row.<\/li>\n<li><code>$filename<\/code> &#8211; Define the name of the excel file to be downloaded.<\/li>\n<li><code>$fields<\/code> &#8211; Define the column named of the excel sheet.<\/li>\n<li><code>$excelData<\/code> &#8211; Add the first row to the excel sheet as a column name.<\/li>\n<li>Fetch member&#8217;s data from the database and add to the row of the excel sheet.<\/li>\n<li>Define headers to force the file to download.<\/li>\n<li>Render data of excel sheet.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php&nbsp; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;database&nbsp;configuration&nbsp;file&nbsp; <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'dbConfig.php'<\/span><span style=\"color: #007700\">;&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Filter&nbsp;the&nbsp;excel&nbsp;data&nbsp; <br \/><\/span><span style=\"color: #007700\">function&nbsp;<\/span><span style=\"color: #0000BB\">filterData<\/span><span style=\"color: #007700\">(&amp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">){&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">preg_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\/\\t\/\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"\\\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">preg_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\/\\r?\\n\/\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">\"\\\\n\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">strstr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">))&nbsp;<\/span><span style=\"color: #0000BB\">$str&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'\"'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">str_replace<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'\"\"'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$str<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'\"'<\/span><span style=\"color: #007700\">;&nbsp; <br \/>}&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Excel&nbsp;file&nbsp;name&nbsp;for&nbsp;download&nbsp; <br \/><\/span><span style=\"color: #0000BB\">$filename&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'members_export_'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">date<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Ymd_His'<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'.xls'<\/span><span style=\"color: #007700\">; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Column&nbsp;names&nbsp; <br \/><\/span><span style=\"color: #0000BB\">$fields&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #DD0000\">'ID'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'NAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'EMAIL'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'GENDER'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'COUNTRY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'CREATED'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'STATUS'<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Display&nbsp;column&nbsp;names&nbsp;as&nbsp;first&nbsp;row&nbsp; <br \/><\/span><span style=\"color: #0000BB\">$excelData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">implode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">array_values<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$fields<\/span><span style=\"color: #007700\">))&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">\"\\n\"<\/span><span style=\"color: #007700\">;&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Query&nbsp;to&nbsp;fetch&nbsp;records&nbsp;from&nbsp;database&nbsp; <br \/><\/span><span style=\"color: #0000BB\">$sql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;id,&nbsp;first_name,&nbsp;last_name,&nbsp;email,&nbsp;gender,&nbsp;country,&nbsp;created,&nbsp;status&nbsp;FROM&nbsp;members&nbsp;ORDER&nbsp;BY&nbsp;id&nbsp;ASC\"<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;each&nbsp;row&nbsp;of&nbsp;the&nbsp;data&nbsp; <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">&amp;&amp;&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(<\/span><span style=\"color: #0000BB\">$row&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch_assoc<\/span><span style=\"color: #007700\">())&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;==&nbsp;<\/span><span style=\"color: #0000BB\">1&nbsp;<\/span><span style=\"color: #007700\">?&nbsp;<\/span><span style=\"color: #DD0000\">'Active'&nbsp;<\/span><span style=\"color: #007700\">:&nbsp;<\/span><span style=\"color: #DD0000\">'Inactive'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">trim<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'first_name'<\/span><span style=\"color: #007700\">]&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'&nbsp;'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'last_name'<\/span><span style=\"color: #007700\">]); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$lineData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'email'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'gender'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'country'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'created'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$status<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">array_walk<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$lineData<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'filterData'<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$excelData&nbsp;<\/span><span style=\"color: #007700\">.=&nbsp;<\/span><span style=\"color: #0000BB\">implode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"\\t\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">array_values<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$lineData<\/span><span style=\"color: #007700\">))&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">\"\\n\"<\/span><span style=\"color: #007700\">;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br \/>} <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Headers&nbsp;for&nbsp;download&nbsp; <br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Content-Type:&nbsp;application\/vnd.ms-excel\"<\/span><span style=\"color: #007700\">);&nbsp; <br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Content-Disposition:&nbsp;attachment;&nbsp;filename=\\\"<\/span><span style=\"color: #0000BB\">$filename<\/span><span style=\"color: #DD0000\">\\\"\"<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;excel&nbsp;data&nbsp; <br \/><\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$excelData<\/span><span style=\"color: #007700\">;&nbsp; <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;cleanup <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">)&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">free<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">close<\/span><span style=\"color: #007700\">(); <br \/>exit; <br \/> <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p><u>The above-mentioned solution helps you export data from the database to Excel and save it as a .xls file. If you want to export to Excel in an XLSX file, use the following process.<\/u><\/p>\n<h2>Export Data to Excel and Save it in an XLSX file using PHP<\/h2>\n<p>In this example script, we will export data from the MySQL database in an excel file using PHP and save it as a <code>.xlsx<\/code> file.<\/p>\n<p><b>PHP XLSX Generator Library (PhpXlsxGenerator.class.php):<\/b><br \/>\nThe PhpXlsxGenerator class handle the Excel file generation process and export data in a <code>.xlsx<\/code> file using PHP.<\/p>\n<ul>\n<li>You can download the PhpXlsxGenerator library file from <a href=\"https:\/\/github.com\/codexworld\/PhpXlsxGenerator\" target=\"_blank\">here<\/a>.<\/li>\n<\/ul>\n<p><span class=\"note\">Note that:<\/span> All the required files including this PhpXlsxGenerator library are included in our source code, you do not require to install it separately.<\/p>\n<p><b>Export Data from Database to Excel in PHP:<\/b><br \/>\nThe following code will export data from the MySQL database and download it as an excel file (.xlsx) using PHP.<\/p>\n<ul>\n<li>Include the database configuration file to connect to the MySQL database.<\/li>\n<li>Include the PhpXlsxGenerator class file to generate the Excel file.<\/li>\n<li>Define the name of the Excel file to be downloaded.<\/li>\n<li>Define the column headings in an array and add it as the first row of the export data array.<\/li>\n<li>Fetch records from the database and store them in the export data array.<\/li>\n<li>Create an instance of the PhpXlsxGenerator class using the <b>fromArray()<\/b> method and pass the export data array.<\/li>\n<li>Call the <b>downloadAs()<\/b> method and set the name of the Excel file to download it.<\/li>\n<li>Finally, free the result set and close the database connection.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;database&nbsp;configuration&nbsp;file <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'dbConfig.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;XLSX&nbsp;generator&nbsp;library <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'PhpXlsxGenerator.class.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Excel&nbsp;file&nbsp;name&nbsp;for&nbsp;download <br \/><\/span><span style=\"color: #0000BB\">$filename&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'members_export_'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">date<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Ymd_His'<\/span><span style=\"color: #007700\">)&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'.xlsx'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Define&nbsp;header&nbsp;row <br \/><\/span><span style=\"color: #0000BB\">$excelData<\/span><span style=\"color: #007700\">[]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'ID'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'NAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'EMAIL'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'GENDER'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'COUNTRY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'CREATED'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'STATUS'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Query&nbsp;to&nbsp;fetch&nbsp;the&nbsp;same&nbsp;fields&nbsp;used&nbsp;in&nbsp;the&nbsp;UI <br \/><\/span><span style=\"color: #0000BB\">$sql&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;id,&nbsp;first_name,&nbsp;last_name,&nbsp;email,&nbsp;gender,&nbsp;country,&nbsp;created,&nbsp;status&nbsp;FROM&nbsp;members&nbsp;ORDER&nbsp;BY&nbsp;id&nbsp;ASC\"<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">query<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sql<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;row's&nbsp;data&nbsp;to&nbsp;excel&nbsp;data&nbsp;array <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$result&nbsp;<\/span><span style=\"color: #007700\">&amp;&amp;&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(<\/span><span style=\"color: #0000BB\">$row&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch_assoc<\/span><span style=\"color: #007700\">())&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'status'<\/span><span style=\"color: #007700\">]&nbsp;==&nbsp;<\/span><span style=\"color: #0000BB\">1&nbsp;<\/span><span style=\"color: #007700\">?&nbsp;<\/span><span style=\"color: #DD0000\">'Active'&nbsp;<\/span><span style=\"color: #007700\">:&nbsp;<\/span><span style=\"color: #DD0000\">'Inactive'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">trim<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'first_name'<\/span><span style=\"color: #007700\">]&nbsp;.&nbsp;<\/span><span style=\"color: #DD0000\">'&nbsp;'&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'last_name'<\/span><span style=\"color: #007700\">]); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$lineData&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;array(<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'id'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'email'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'gender'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'country'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$row<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'created'<\/span><span style=\"color: #007700\">],&nbsp;<\/span><span style=\"color: #0000BB\">$status<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$excelData<\/span><span style=\"color: #007700\">[]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">$lineData<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Export&nbsp;data&nbsp;to&nbsp;excel&nbsp;and&nbsp;download&nbsp;as&nbsp;xlsx&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$xlsx&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">CodexWorld\\PhpXlsxGenerator<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">fromArray<\/span><span style=\"color: #007700\">(&nbsp;<\/span><span style=\"color: #0000BB\">$excelData&nbsp;<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$xlsx<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">downloadAs<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$filename<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;cleanup <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">)&nbsp;<\/span><span style=\"color: #0000BB\">$result<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">free<\/span><span style=\"color: #007700\">(); <br \/><\/span><span style=\"color: #0000BB\">$conn<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">close<\/span><span style=\"color: #007700\">(); <br \/>exit; <br \/> <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p>If you want to save XLSX file on the server instead of downloading it, use the <b>saveAs()<\/b> method of PhpXlsxGenerator class.<\/p>\n<pre><span style=\"color: #0000BB\">$xlsx<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">saveAs<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'members-data.xlsx'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/export-html-table-data-to-excel-using-javascript\/\">Export HTML Table Data to Excel using JavaScript<\/a><\/span><\/p>\n<h2>Conclusion<\/h2>\n<p>If you want to add an export option to the data list, the <b>export to excel<\/b> feature is perfect for it. With the export option, the user can download the data in an excel file and save it in a local drive. You can use this simple PHP 8 export Excel code to add export data functionality in the web application using PHP.<br \/>\nDownload the complete source code from <a href=\"https:\/\/www.codexworld.com\/downloads\/export-data-to-excel-in-php\/\" target=\"_blank\">Download Source Code<\/a> button below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Export data feature is very useful where the data is saved on the local drive for offline uses. Export data to file functionality provides a user-friendly way to maintain a large number of data in <\/p>\n","protected":false},"author":1,"featured_media":5438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[326,314,19,14],"class_list":["post-567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-excel","tag-export","tag-mysql","tag-php","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Export MySQL Data to Excel using PHP 8 - CodexWorld<\/title>\n<meta name=\"description\" content=\"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Export MySQL Data to Excel using PHP 8 - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-01T09:35:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-08T10:00:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Export MySQL Data to Excel using PHP 8\",\"datePublished\":\"2015-05-01T09:35:37+00:00\",\"dateModified\":\"2025-10-08T10:00:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/\"},\"wordCount\":923,\"commentCount\":22,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png\",\"keywords\":[\"Excel\",\"Export\",\"MySQL\",\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/\",\"name\":\"Export MySQL Data to Excel using PHP 8 - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png\",\"datePublished\":\"2015-05-01T09:35:37+00:00\",\"dateModified\":\"2025-10-08T10:00:49+00:00\",\"description\":\"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png\",\"width\":1920,\"height\":1080,\"caption\":\"export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/export-data-to-excel-in-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Export MySQL Data to Excel using PHP 8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Export MySQL Data to Excel using PHP 8 - CodexWorld","description":"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/","og_locale":"en_US","og_type":"article","og_title":"Export MySQL Data to Excel using PHP 8 - CodexWorld","og_description":"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.","og_url":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2015-05-01T09:35:37+00:00","article_modified_time":"2025-10-08T10:00:49+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Export MySQL Data to Excel using PHP 8","datePublished":"2015-05-01T09:35:37+00:00","dateModified":"2025-10-08T10:00:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/"},"wordCount":923,"commentCount":22,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","keywords":["Excel","Export","MySQL","PHP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/","url":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/","name":"Export MySQL Data to Excel using PHP 8 - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","datePublished":"2015-05-01T09:35:37+00:00","dateModified":"2025-10-08T10:00:49+00:00","description":"PHP Export to Excel tutorial - Export data from the database in an Excel file using PHP and MySQL. Example code to export data to excel in PHP and download as an excel file.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","width":1920,"height":1080,"caption":"export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/export-data-to-excel-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Export MySQL Data to Excel using PHP 8"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/05\/export-data-to-excel-xlsx-file-from-mysql-database-using-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-99","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=567"}],"version-history":[{"count":18,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":5913,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/567\/revisions\/5913"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5438"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}