473,505 Members | 13,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import database from excel sheet to PHP

1 New Member
Can any one help in importing database from excel sheet to PHP?
Bye,
Sound.
Jan 19 '07 #1
3 6596
subash
33 New Member
Hi,

If your excel file is in CSV format you can do the following

1. In PHP you can use fgetcsv command to process and try insert into mysql on help of mysql commands

2.The best method is try using the following mysql statement

[PHP]
LOAD DATA LOCAL INFILE '/importfile.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3);
[/PHP]


Subash :)
Jan 21 '07 #2
ronverdonk
4,258 Recognized Expert Specialist
Can any one help in importing database from excel sheet to PHP?
Bye,
Sound.
Do you want to import a database FROM an Excel sheet INTO PHP? Obviously not. So it is either:

- import an Excel sheet (not all cells) into a MySQL database table using PHP
- import an Excel sheet (all cells) into a MySQL database table using LOADFILE
- export a MySQL table into an Excel XML sheet using PHP.

Which one is it?

Ronald :cool:
Jan 21 '07 #3
ergocho
2 New Member
If you want to import an exel sheet with php to your database, you must have sheet by sheet save as csv and then you can use this ex code


[PHP]<?php
//reading csv file
$fname="file.csv";
$fp=fopen($fname,"r") or die("csv Error");
$line = fgets( $fp, 2024 );
//conexion with db started
$c=mysql_connect("localhost","root","");
if(!$c)
{
die("Not Conected");
}
if(!mysql_select_db("dbspl"))
{
die("Table Error");
}

while(!feof($fp))
{
list($var1,$var2,$var3) =split( ",", $line); //list of variables to import
$line = fgets( $fp, 2024 );
$ctd=$ctd+1;
if($ctd > 1)
{
$var1=strtoupper($var1);//Uppercase

if($loca!="" && $pudoc!="")
{
if(!($inserc=mysql_query("INSERT INTO table (field1,field2,field3)
VALUES('$var1','$var2','$var3')")))
{
echo'<center>';
echo'<br>';
echo mysql_error();
echo'<br>';
echo"User Inser Error";
echo'</center>';
}
}//
}// if($ctd > 1)
} // while(!feof($fp))
fclose($fp);
?> [/PHP]
Feb 7 '07 #4

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

Similar topics

8
6538
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
1
2189
by: Peter Stojkovic | last post by:
I am importing data from an EXCEL XLS-File via OLEDB-Provider The command is SELECT * from Everything works fine if the first sheet is named sheet1 But sometimes the name is not known...
10
11790
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
2
3479
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called...
8
8561
by: FireGeek | last post by:
I have a database that is split appropriately. Annually, we need to add data from .xls files. I have added code so with a click of a button, it will import this data as a new table into the...
3
1933
by: Simon | last post by:
Dear reader, One table in database A...mdb is linked to a table in database B..mdb. As A..mdb is open and in B...mdb starts an excel import procedure the progress bar shows that the import...
3
3263
by: Kbalz | last post by:
Hello, I'm trying to create an application for a friend's business. He gets Excel Spreadsheets from a lab - he would like for his partners to be able to Upload this Sheet to a website, and have the...
1
8694
by: baling | last post by:
Hi.... Hi everybody, i have a code that i make in VBA and know I want to use this code in to VB6. But i don't know how to use that code in to VB 6.0 Please correct this code so i can use it in VB...
0
2715
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
7
12037
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
7213
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,...
1
7017
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
5610
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,...
1
5026
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...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.