title: How to import data from excel to mysql database using php
body: <p>I am using PHPExcel to import a XLSX file to my related database. But while running the function I am getting the error. My code looks like shown below.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>   &lt;?php    if (!defined ('BASEPATH')) exit ('No direct access allowed');
        class ExcelController extends CI_Controller
        {
  
  
        public function index()
        {
            //load library excel
            $this-&gt;load-&gt;library('excel');
  
            //Here i used microsoft excel 2007
            $objReader= PHPExcel_IOFactory::createReader('Excel2007');
  
            //Set to read only
            $objReader-&gt;setReadDataOnly(true);
  
  
            //Load excel file
            $objPHPExcel=$objReader-&gt;load('data.xls'); // error in this line
            $objWorksheet=$objPHPExcel-&gt;setActiveSheetIndex(0);
  
            //load model
  
            $this-&gt;load-&gt;model('user_model');
  
            //loop from first data untill last data
            for($i=2;$i&lt;=77;$i++)
            {
                $name= $objWorksheet-&gt;getCellByColumnAndRow(0,$i)-&gt;getValue();
                $address= $objWorksheet-&gt;getCellByColumnAndRow(1,$i)-&gt;getValue();
  
                $data_user=array('name'=&gt;$name, 'username'=&gt;$address);
  
                $this-&gt;user_model-&gt;add_data($data_user);
            }
  
        }
  
  
    }           
  
    ?&gt;
  </code></pre>
  
  <p><strong>model:</strong></p>
  
  <pre><code> &lt;?php
  if (!defined ('BASEPATH')) exit ('No direct access allowed');
      class User_model extends CI_Controller
  {
      public function __construct() {
          parent::__construct();
      }
  
      public function add_data($data_user)
      {
          $this-&gt;load-&gt;database();
  
          $this-&gt;db-&gt;insert('data',$data_user);
          return $this-&gt;db-&gt;insert_id();
  
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Error in my code:</p>
  
  <pre><code>Fatal error: Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open data.xls for reading! File does not exist.' in C:\xampp\htdocs\ci_excel\application\third_party\PHPExcel\Reader\Excel2007.php:347 Stack trace: #0 C:\xampp\htdocs\ci_excel\application\controllers\excelcontroller.php(19): PHPExcel_Reader_Excel2007-&gt;load('data.xls') #1 [internal function]: ExcelController-&gt;index() #2 C:\xampp\htdocs\ci_excel\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #3 C:\xampp\htdocs\ci_excel\index.php(202): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\ci_excel\application\third_party\PHPExcel\Reader\Excel2007.php on line 347
  </code></pre>