473,671 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i import data from *.xls file into MYSQL without using Com Object

245 New Member
Hey all,
I want to import data into mysql Database without using Com object using php technique from a Microsoft Excel File?
Apr 17 '09 #1
5 6434
Dormilich
8,658 Recognized Expert Moderator Expert
at first glance I'd say that's impossible, you have to read the file format somehow (and since it's a proprietary format…).
Apr 17 '09 #2
neovantage
245 New Member
Yeh but you can see that
PHP MyAdmin give the option of importing data through Excel File without using Com object. Is there any special technique PHPMyadmin Using or PHPMYadmin has it's own algorithm.
Apr 17 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
this is beyond my skill level…
Apr 17 '09 #4
Ciary
247 Recognized Expert New Member
have you tried this?
http://www.webmasterworld.com/php/3334579.htm
Apr 17 '09 #5
anouarabslam
1 New Member
Step1 Form: save it as enterfile.php
Expand|Select|Wrap|Line Numbers
  1.  
  2. <form method="post" enctype="multipart/form-data" action="import.php">
  3.     <table width="628" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#eeeeee">
  4.     <tr>
  5.       <td width="219"><font size=3><b>Selectionner votre fichier *.csv :</b></font></td>
  6.       <td width="244" align="center"><input type="file" name="userfile" value="userfile"></td>
  7.       <td width="137" align="center">
  8.         <input type="submit" value="Envoyer" name="envoyer" >
  9.       </td>
  10.     </tr>
  11.     </table>
  12.     </form>
  13.  


Step2 create connect script: save it as connect.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // paramètres de connexion
  3. $hostname_smoby = "localhost"; /
  4. $database_smoby = "sample"; 
  5. $username_smoby = "root"; 
  6. $password_smoby = "";
  7. $db = mysql_connect($hostname_smoby, $username_smoby, $password_smoby) or trigger_error(mysql_error(),E_USER_ERROR);
  8. mysql_select_db($database_smoby)or trigger_error(mysql_error(),E_USER_ERROR); 
  9. ?>
  10.  

Step 3 import.php
Expand|Select|Wrap|Line Numbers
  1.     <a name="haut"></a>
  2.     <?php
  3.     // vérification sur la session authentification (la session est elle enregistrée ?)
  4.     // ici les éventuelles actions en cas de réussite de la connexion
  5.      require_once('connect.php'); 
  6. //===========================================================
  7. //
  8. // Code de : Xavier Manzoni
  9. // Email : kaptain_kavern_23@hotmail.com
  10. // Date: 23 Novembre 2004
  11. // Objectif :
  12. //            Selection d'un fichier xls enregistre sous format 
  13. // CSV (separateur ";") puis enregistrement dans la base.
  14. //            Base: smoby
  15. //            Table: bdd
  16. //===========================================================
  17.  
  18.  
  19. //=========================
  20. // Traitement des donnees
  21. //=========================
  22.  
  23. //recupere le nom du fichier indiqué par l'user
  24.  $fichier=$_FILES["userfile"]["name"];
  25.  
  26. // ouverture du fichier en lecture    
  27. if ($fichier)
  28.     {
  29.     //ouverture du fichier temporaire 
  30.     $fp = fopen ($_FILES["userfile"]["tmp_name"], "r"); 
  31.     }
  32. else{ 
  33.     // fichier inconnu 
  34.     ?>
  35.     <p align="center" >- Importation échouée -</p>
  36.     <p align="center" ><b>Désolé, mais vous n'avez pas spécifié de chemin valide ...</b></p>
  37.     <?php
  38.       exit(); 
  39.     }
  40. // declaration de la variable "cpt" qui permettra de conpter le nombre d'enregistrement réalisé
  41. $cpt=0;
  42.  
  43. // importation    
  44. while (!feof($fp))
  45. {
  46.   $ligne = fgets($fp,4096);  
  47.   // on crée un tableau des élements séparés par des points virgule
  48.   $liste = explode(";",$ligne); 
  49.   // premier élément
  50.   $liste[0] = ( isset($liste[0]) ) ? $liste[0] : Null;
  51.   $liste[1] = ( isset($liste[1]) ) ? $liste[1] : Null;
  52.   $liste[2] = ( isset($liste[2]) ) ? $liste[2] : Null;
  53.   $liste[3] = ( isset($liste[3]) ) ? $liste[3] : Null;
  54.  
  55.   $champs0=$liste[0];
  56.   $champs1=$liste[1];
  57.   $champs2=$liste[2];
  58.   $champs3= $liste[3];
  59.  
  60.  
  61.       // pour eviter qu un champs "nom" du fichier soit vide
  62.     if ($champs1!='')
  63.         {
  64.         // nouvel ajout, compteur incrémenté
  65.         $cpt++; 
  66.         // requete et insertion ligne par ligne 
  67.         // champs1 id en general dc on affecte pas de valeur
  68.  
  69.           $result= mysql_query("INSERT INTO names  VALUES('','$champs0','$champs1','$champs2','$champs3')");
  70.  
  71.         }
  72. }
  73.  
  74. // fermeture du fichier
  75. fclose($fp);
  76.  
  77.  
  78. //==================
  79. // FIN
  80. //==================
  81. ?>
  82. <br /><br />Nombre de valeurs nouvellement enregistrées: <b><?php echo $cpt;?></b>.<br /><br />
  83.  
I wish that help sorry for the frensh explaination inside the php scripts . it was just fast reply .have funn with php
Mar 9 '10 #6

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

Similar topics

3
11755
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
2
12388
by: Damien | last post by:
Hi to all, I need to design an import/export system. Data comes from a filemaker pro DB in a big CSV file. Some alterations are made on the data as it is imported into my mysql table. Data is something like :id,text1html, text1raw,... . Problems : 1. Texts can contain html tags, including entities (&quot; etc), so using only the ';' as separator does not work. 2. Some line are so long that is appears php breaks them down, so I lose
2
22707
by: jet | last post by:
Hi, Maybe this is an easy task, but I'm having a really hard time figuring out how to do this. I'm a complete newbie to SQL Server. I have a database dump file from MySQL that's in .sql format. I'm trying to figure out how to import that into SQL Server 2000 so that I'll be able to manipulate it in a gui format, rather than command line. I can't find any import that takes a .sql file. I've been trying to load it into the query...
4
12706
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as though the file may be too big! When I try to do it via command line: mysql -u root --host=localhost printing < ./printing.txt It eventually errors out with a "syntax error on line X" and only about
7
33402
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I need to know else (e.g. Navicat)? Thanks Phil
10
2109
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has insight into the FASTEST way to read in the data and chop it up ahead of posting it into the DB. So far, things work, but they are far slower than expected.
0
3471
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer of "none" (this is how I read to do it from newsgroups). When I use the Query window in phpmyadmin to import the text file, it waits a while, then returns an error: #1064 - You have an error in your SQL syntax; check the manual that...
7
4188
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did things this way because it made things easy. Well, I'm the person that has to put up with the long-term headache. Anywho, someone at work wants things sped up, so what I'm looking at doing is this for each client:
2
2233
by: GarryJones | last post by:
(I am sorry if this is the wrong group for this posting, I cant find a group on usenet for phpmyadmin, but maybe someone would be nice enough to answer me anyway....) I need to import data into a simple table The table has three fields. The first is an auto increment value, the second the current time and date (the 14 character version), and a field with some data. This works okay in SQL mode INSERT INTO all_epst VALUES...
0
8485
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8930
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...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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,...
0
8677
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4227
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
4417
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1816
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.