473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to import the Excel data in mysql database using php script?

147 100+
Hi,
I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made? Please help me out

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $strPath = realpath(basename(getenv($_SERVER['SCRIPT_FILENAME'])));
  3. echo $strPath;
  4.  
  5.  
  6. $excel_app = new COM("Excel.application") or Die ("Did not connect");
  7. $Workbook = $excel_app->Workbooks->Open('C:\san1.xls') or Die('Did not open filename');
  8. $Worksheet = $Workbook->Worksheets(1);
  9. $Worksheet->activate;
  10.  
  11.  
  12.  
  13. $username = "root";
  14. $hostname = "localhost"; 
  15.  
  16. //connection to the database
  17. $dbhandle = mysql_connect($hostname, $username) or die("Unable to connect to MySQL");
  18. echo "Connected to MySQL<br>";
  19.  
  20.  
  21. //select a database to work with
  22. $selected = mysql_select_db("academics",$dbhandle) or die("Could not select examples");
  23.  
  24. echo "hi";
  25. $i=2;  
  26. while($Worksheet->Cells->Item($i,1) != "")  
  27. {  
  28.   $strSQL = "";  
  29.   $strSQL .= "INSERT INTO tbl";  
  30.   $strSQL .= "(rollno,crseno,marks,grade,att)";  
  31.   $strSQL .= "VALUES";  
  32.   $strSQL .= "('".$Worksheet->Cells->Item($i,1)."','".$Worksheet->Cells->Item($i,2)."' ";  
  33.   #$strSQL .= ",'".$Worksheet->Cells->Item($i,3)."','".$Worksheet->Cells->Item($i,4)."' ";  
  34.   $strSQL .= ",'".$Worksheet->Cells->Item($i,3)."','".$Worksheet->Cells->Item($i,4)."') ";  
  35.   mysql_query($strSQL);  
  36.   $i++;  
  37. }  
  38.  
  39. //*** Close MySQL ***//  
  40. @mysql_close($dbhandle);  
  41.  
  42. //*** Close & Quit ***//  
  43. $excel_app->Application->Quit();  
  44. $excel_app = null;  
  45. $Workbook = null;  
  46. $Worksheet = null; 
  47.  
  48.  
  49. ?>
  50.  

Thanks in advance
May 14 '11 #1
1 12111
ronverdonk
4,258 Expert 4TB
I'd suggest to use a free class for this, like
http://www.phpclasses.org/package/62...XLS-files.html
Jun 9 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ramyanet | last post by:
Dear all, Is there any way to directly transfer the data from excel to mysql database without using any tools,but thro coding. pls help me .hope i'll get a soln soon. Thanks Regds,
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
9
by: christopher_board | last post by:
Hi all. I am trying to connect to a MySQL Database using PHP on a local machine using locahost. I am using the following code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass =...
0
by: levis123 | last post by:
hi, anybody know how to import excel data into sql server using asp.net (vb.net). i've read some articles in the internet, however, try to implement it seems...still have problems...any1 who solved...
0
by: ghazal01978 | last post by:
hi all I need some help how to import excel data into sql server using vb6? I have a sub , and used that but for many fieldes had problem , although those fields had text format data , vb...
9
sukumar 123
by: sukumar 123 | last post by:
need to import Excel data into Mysql database using coldfusion script. How can i do it. Is there any utility or any script can do it. Thanks in advance.
3
by: chirag1989 | last post by:
how can i add data to database using excel through asp actual i wanted to use datagrid but as its not supported by asp so i want to try dat by excel can any one just provide me a short code...
1
by: twinkle2010 | last post by:
Hi I am a new web programmer.I got an issue that reads the excel sheet data and store it to MYSQL database using php. I dont have any idea on that. can you help me?
6
by: mfaisalwarraich | last post by:
Hi everyone, I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP. I have looked at google and searched for it on...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.