473,657 Members | 2,572 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 6610
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.cs v";
$fp=fopen($fnam e,"r") or die("csv Error");
$line = fgets( $fp, 2024 );
//conexion with db started
$c=mysql_connec t("localhost"," root","");
if(!$c)
{
die("Not Conected");
}
if(!mysql_selec t_db("dbspl"))
{
die("Table Error");
}

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

if($loca!="" && $pudoc!="")
{
if(!($inserc=my sql_query("INSE RT 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
6547
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 macro. (I'll get to using VB later on). What I would like to do is import a single workbook w/three seperate worksheets into three seperate access tables AND truncate the time stamp that is used in the excell sheet via a macro.
1
2199
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 by my application and the import failes.
10
11810
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 .NET. The data in Excel is not in structured columns but can exist everywhere in the workbook. For example if I am supposed to import a person and all his/her cars which exist in a workbook I want to be able to create an import protocol and specify...
2
3490
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 SubSAT and I need to get specific data from that into the database. I'm finding that if I have the workbook open on my desktop then the SubSAT % complete and the High level plan % come in fine, but as soon as the workbook is closed they come...
8
8585
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 database. The problem is that the code is on the front end and thus it imports the data/new table into the front ent. How can I accomplish an import (with the click of a button) into the back end and link it to the front end? THANKS
3
1942
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 procedure stops. After the A...mdb is closed the excel import procedure runs smoothly. The linked table in A..mdb is not the same table as used for the excel import procedure. Is there
3
3271
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 page import the sheet and add the data to his existing SS 2005 database. Is this possible, and where should I begin looking? Thanks,
1
8705
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 6.0. Code: --- use in mainform ------- Option Compare Database Option Explicit
0
2742
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 perfectly but i when i upload the file again it should include only the new records by checking the existence of ID field which i use as primary key. For now it pops up the message"Table Exists already"Could anyone help me pls? Dim...
7
12060
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
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.