Page 1 of 2 12 LastLast
Results 1 to 10 of 19

how to import data from excel to mysql using PHP

This is a discussion on how to import data from excel to mysql using PHP within the Programming forums, part of the Web Designing & Development category; how to import data from excel to mysql using PHP...

  1. #1
    Senior Member Array
    Join Date
    Mar 2010
    Posts
    179

    Default how to import data from excel to mysql using PHP

    how to import data from excel to mysql using PHP

  2. #2
    Junior Member Array
    Join Date
    Aug 2010
    Posts
    4

    Default Re: how to import data from excel to mysql using PHP

    Hi,
    If there is only a few, you can enter it manually using something like phpMyAdmin or a tool such as Navicat. If there is too much to manually enter, you can use a software tool based on the import. Once again, Navicat here.Otherwise can help, you can write the script itself using PHP to import your Excel file to scan and enter data into the database. Be sure to save your Excel file as a CSV file.

  3. #3
    Junior Member Array
    Join Date
    Sep 2010
    Posts
    4

    Default Re: how to import data from excel to mysql using PHP

    Explore fgetcsv()

    php.net/manual/en/function.fgetcsv.php

  4. #4
    Member Array
    Join Date
    Nov 2010
    Posts
    94

    Default Re: how to import data from excel to mysql using PHP

    Quote Originally Posted by ExpertsGuide View Post
    Explore fgetcsv()

    php.net/manual/en/function.fgetcsv.php
    That's realy cool

  5. #5
    Junior Member Array
    Join Date
    Sep 2010
    Posts
    25

    Default Re: how to import data from excel to mysql using PHP

    The simplest way to use Excel imports and exports with PHP is to use the PEAR Excel functions. I've just finished working on a project where I've had to export to Excel directly from PHP, and another developer produced the import script, and it's all pretty easy wen you use this.

  6. #6
    Senior Member Array maxelink's Avatar
    Join Date
    Nov 2010
    Location
    Webmaster
    Posts
    142

    Default Re: how to import data from excel to mysql using PHP

    hi mate ,

    Excel-MySQL is a very easy to use , yet powerful , tool to import any Excel spreadsheets into MySQL database or publish any MySQL database as an Excel file . Supporting many advanced features like Conversion schedule, Selecting certain tables or fields , command line , .etc

  7. #7
    Junior Member Array
    Join Date
    Sep 2010
    Posts
    25

    Default Re: how to import data from excel to mysql using PHP

    Try this... It may help you to solve your problem.

    Code:
    PHP Syntax
     
    <?
     
    /********************************************************************************************/
    /* Code at http://legend.ws/blog/tips-tricks/csv-php-mysql-import/
    /* Edit the entries below to reflect the appropriate values
    /********************************************************************************************/
    $databasehost = "localhost";
    $databasename = "test";
    $databasetable = "sample";
    $databaseusername ="test";
    $databasepassword = "";
    $fieldseparator = ",";
    $lineseparator = "\n";
    $csvfile = "E:\Webcache\AA ONLINE\test1\english1.csv";
    /********************************************************************************************/
    /* Would you like to add an ampty field at the beginning of these records?
    /* This is useful if you have a table with the first field being an auto_increment integer
    /* and the csv file does not have such as empty field before the records.
    /* Set 1 for yes and 0 for no. ATTENTION: don't set to 1 if you are not sure.
    /* This can dump data in the wrong fields if this extra field does not exist in the table
    /********************************************************************************************/
    $addauto = 0;
    /********************************************************************************************/
    /* Would you like to save the mysql queries in a file? If yes set $save to 1.
    /* Permission on the file should be set to 777. Either upload a sample file through ftp and
    /* change the permissions, or execute at the prompt: touch output.sql && chmod 777 output.sql
    /********************************************************************************************/
    $save = 1;
    $outputfile = "output.sql";
    /********************************************************************************************/
     
     
    if(!file_exists($csvfile)) {
    	echo "File not found. Make sure you specified the correct path.\n";
    	exit;
    }
     
    $file = fopen($csvfile,"r");
     
    if(!$file) {
    	echo "Error opening data file.\n";
    	exit;
    }
     
    $size = filesize($csvfile);
     
    if(!$size) {
    	echo "File is empty.\n";
    	exit;
    }
     
    $csvcontent = fread($file,$size);
     
    fclose($file);
     
    $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
    @mysql_select_db($databasename) or die(mysql_error());
     
    $lines = 0;
    $queries = "";
    $linearray = array();
     
    foreach(split($lineseparator,$csvcontent) as $line) {
     
    	$lines++;
     
    	$line = trim($line," \t");
     
    	$line = str_replace("\r","",$line);
     
    	/************************************************************************************************************
    	This line escapes the special character. remove it if entries are already escaped in the csv file
    	************************************************************************************************************/
    	$line = str_replace("'","\'",$line);
    	/***********************************************************************************************************/
     
    	$linearray = explode($fieldseparator,$line);
     
    	$linemysql = implode("','",$linearray);
     
    	if($addauto)
    		$query = "insert into $databasetable values('','$linemysql');";
    	else
    		$query = "insert into $databasetable values('$linemysql');";
     
    	$queries .= $query . "\n";
     
    	@mysql_query($query);
    }
     
    @mysql_close($con);
     
    if($save) {
     
    	if(!is_writable($outputfile)) {
    		echo "File is not writable, check permissions.\n";
    	}
     
    	else {
    		$file2 = fopen($outputfile,"w");
     
    		if(!$file2) {
    			echo "Error writing to the output file.\n";
    		}
    		else {
    			fwrite($file2,$queries);
    			fclose($file2);
    		}
    	}
     
    }
     
    echo "Found a total of $lines records in this csv file.\n";
     
     
    ?>

  8. #8
    Junior Member Array
    Join Date
    Nov 2010
    Location
    Karachi, Pakistan
    Posts
    1

    Default Re: how to import data from excel to mysql using PHP

    First convert xls file to .csv then use fgetcsv() function.

  9. #9
    Member Array
    Join Date
    Nov 2010
    Posts
    80

    Default Re: how to import data from excel to mysql using PHP

    Thank you for sharing the your Experience..

  10. #10
    Junior Member Array
    Join Date
    Aug 2010
    Posts
    21

    Default Re: how to import data from excel to mysql using PHP

    I encounter these kinds of questions before, thanks for sharing.




Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 09-07-2011, 09:20 AM
  2. Replies: 1
    Last Post: 09-06-2011, 04:41 PM
  3. [WTS] Over 30 mysql MySQL databases worth $6250 now just $3750
    By immediate in forum Website Content & Scripts For Sale
    Replies: 1
    Last Post: 01-22-2010, 03:10 PM
  4. [WTS] 32 Original MySQL Niche Content Databases On Sale (Industrial Data & Facts)
    By immediate in forum Website Content & Scripts For Sale
    Replies: 0
    Last Post: 12-23-2009, 01:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |