If you have Excel files that need to be imported into MySQL, you can
import them easily with PHP. First, you will need to download some
prerequisites:

PHPExcelReader – http://sourceforge.net/projects/phpexcelreader/
Spreadsheet_Excel_Writer – http://pear.php.net/package/Spreadsheet_Excel_Writer

Once you’ve downloaded both items, upload them to your server. Your
directory listing on your server should have two directories: Excel (from PHPExcelReader) and Spreadsheet_Excel_Writer-x.x.x (from Spreadsheet_Excel_Writer). To work around a bug in PHPExcelReader, copy oleread.inc from the Excel directory into a new path:

Spreadsheet/Excel/Reader/OLERead.php

The PHPExcelReader code will expect OLERead.php to be
in that specific location. Once that is complete, you’re ready to use
the PHPExcelReader class. I made an example Excel spreadsheet like this:

Name                Extension   Email<br />----------------------------------------------------<br />Jon Smith           2001        jsmith@domain.com<br />Clint Jones         2002        cjones@domain.com<br />Frank Peterson      2003        fpeterson@domain.com</pre>
<p>After that, I created a PHP script to pick up the data and insert it into the database, row by row:</p>

<div><table><tbody><tr><td><pre>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></pre></td><td><pre style="font-family: monospace;"><span style="color: rgb(177, 177, 0);">require_once</span> <span>'Excel/reader.php'</span>;<br /><span style="color: rgb(0, 0, 136);">$data</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">new</span> Spreadsheet_Excel_Reader<span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">)</span>;<br /><span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">setOutputEncoding</span><span style="color: rgb(0, 153, 0);">(</span><span>'CP1251'</span><span style="color: rgb(0, 153, 0);">)</span>;<br /><span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">read</span><span style="color: rgb(0, 153, 0);">(</span><span>'exceltestsheet.xls'</span><span style="color: rgb(0, 153, 0);">)</span>;<br /> <br /><span style="color: rgb(0, 0, 136);">$conn</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(153, 0, 0);">mysql_connect</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 255);">"hostname"</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 255);">"username"</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 255);">"password"</span><span style="color: rgb(0, 153, 0);">)</span>;<br /><span style="color: rgb(153, 0, 0);">mysql_select_db</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 255);">"database"</span><span style="color: rgb(51, 153, 51);">,</span><span style="color: rgb(0, 0, 136);">$conn</span><span style="color: rgb(0, 153, 0);">)</span>;<br /> <br /><span style="color: rgb(177, 177, 0);">for</span> <span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$x</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(204, 102, 204);">2</span>; <span style="color: rgb(0, 0, 136);">$x</span> <span style="color: rgb(51, 153, 51);"><</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(153, 0, 0);">count</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">sheets</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 255);">"cells"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">)</span>; <span style="color: rgb(0, 0, 136);">$x</span><span style="color: rgb(51, 153, 51);">++</span><span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br />    <span style="color: rgb(0, 0, 136);">$name</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">sheets</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 255);">"cells"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 136);">$x</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(204, 102, 204);">1</span><span style="color: rgb(0, 153, 0);">]</span>;<br />    <span style="color: rgb(0, 0, 136);">$extension</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">sheets</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 255);">"cells"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 136);">$x</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(204, 102, 204);">2</span><span style="color: rgb(0, 153, 0);">]</span>;<br />    <span style="color: rgb(0, 0, 136);">$email</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">sheets</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 255);">"cells"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 136);">$x</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(204, 102, 204);">3</span><span style="color: rgb(0, 153, 0);">]</span>;<br />    <span style="color: rgb(0, 0, 136);">$sql</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 255);">"INSERT INTO mytable (name,extension,email) <br />        VALUES ('$name',$extension,'$email')"</span>;<br />    <span style="color: rgb(153, 0, 0);">echo</span> <span style="color: rgb(0, 0, 136);">$sql</span><span style="color: rgb(51, 153, 51);">.</span><span style="color: rgb(0, 0, 255);">"<span style="color: rgb(0, 0, 153); font-weight: bold;">\n</span>"</span>;<br />    <span style="color: rgb(153, 0, 0);">mysql_query</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 0, 136);">$sql</span><span style="color: rgb(0, 153, 0);">)</span>;<br /><span style="color: rgb(0, 153, 0);">}</span></pre></td></tr></tbody></table></div>

<p>After the script ran, each row had been added to the database table
successfully. If you have additional columns to insert, just repeat
these lines, using an appropriate variable for each column:</p>

<div><div><pre style="font-family: monospace;"><span style="color: rgb(0, 0, 136);">$variable</span> <span style="color: rgb(51, 153, 51);">=</span> <span style="color: rgb(0, 0, 136);">$data</span><span style="color: rgb(51, 153, 51);">-></span><span style="color: rgb(0, 64, 0);">sheets</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 255);">"cells"</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 136);">$row_number</span><span style="color: rgb(0, 153, 0);">]</span><span style="color: rgb(0, 153, 0);">[</span><span style="color: rgb(0, 0, 136);">$column_number</span><span style="color: rgb(0, 153, 0);">]</span>;