Import Excel File into MySQL Database using PHP

You can easily import your data from any Excel file into MySQL Database using a simple PHP script and PHPExcelReader library.

Steps to Import Excel file data into MySQL using PHP Script

1. Download the following library

PHPExcelReader –

2. After you have downloaded the files, please upload them to your web server.  To work around a small bug in PHPExcelReader, copy file from the Excel directory into a new path: Spreadsheet/Excel/Reader/OLERead.php

The PHPExcelReader code will expect OLERead.php to be in the above specific location. Once that is complete, you’re ready to use the PHPExcelReader class.


$conn = mysql_connect("dataBaseHostName","DataBaseUserName","DataBasePassword");

for ($x = 2; $x < = count($data->sheets[0]["cells"]); $x++) {
    $name = $data->sheets[0]["cells"][$x][1];
    $email = $data->sheets[0]["cells"][$x][2];
    $phone = $data->sheets[0]["cells"][$x][3];
    $sql = "INSERT INTO mytable (name,email,phone) 
        VALUES ('$name',$email,'$phone')";
    echo $sql."\n";
This entry was posted in General. Bookmark the permalink.

Leave a Reply

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