WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
Suraj Thapaliya
Date : Apr 19th 2006
Grade : 3 of 5 (graded 20 times)
Viewed : 20336
File : 4375.zip
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

config.php
<?php
    $host
="localhost";
   
$user_name="username";
   
$password="password";
   
$db="databasename";

   
define("DB",$db);
   
define("HOST",$host);
   
define("USERNAME",$user_name);
   
define("PASSWORD",$password);

?>



fileClass.php
<?php
class exportFile
{
    var
$Query_ID=0;
    var
$connection=0;

    function
connect()
    {
        if(
$this->connection==0) {
           
$this->connection=mysql_connect(HOST,USERNAME,PASSWORD) or die("<b>Database Error</b><br>".mysql_error());
           
$SelectResult = mysql_select_db(DB, $this->connection) or die("Couldnot Select Database".mysql_error());
        } else {
            echo
"Connection Couldnot be Established";
            die();
        }
    }
   
    function
query($sql) {
       
$this->Query_ID=mysql_query($sql,$this->connection);
        if(!
$this->Query_ID) {
            echo
"Query Failed".mysql_error();
        } else {
            return
$this->Query_ID;
        }
    }

    function
exportFileToDatbase($filename,$de,$mode,$tablename,$fieldno)
    {
       
       
$fd=fopen($filename,"$mode");
        while(!
feof($fd)) {
           
$line=fgets($fd,5000);
           
$f=explode($de,$line);
                for(
$i=0;$i<$fieldno;$i++) {
                   
$a[]=trim("'$f[$i]'");
                }   
           
$value=implode(",",$a);
            unset(
$a);
           
$sql="insert into $tablename values($value)";
           
//echo $sql;
           
$this->query($sql);
           
        }
       
    }
   
}
?>




text.txt
Suraj~123
Janaki~213
Sujan Thapaliya~23



Usage Example
<?php
include("config.php");
include(
"fileClass.php");
$objFile=new exportFile;
$objFile->connect();
$objFile->exportFileToDatbase("text.txt","~","r","user",2);
// File name,Seprator,mode,tablename,field
?>



phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
This class splits the results of the query into multiple pages like what the search engine does.
Categories : PHP Classes, PHP, MySQL, Databases
MySQL database class
Categories : PHP, MySQL, Databases, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
 achmad syaifuri wrote : 1888
Great thanks for the code.

btw, i make a cron job to run update database from tester 
logfile. so to prevent duplicate data, i have add count 
lines at the txt files and save it the line number at temp 
file.

so in the next cron jobs, query mysql only starting base 
on the line number at temp file compare with the actual 
txt file.

please advice, how to modify the class function, since my 
counting lines always error.



.: Foery :.
 
 karthik s wrote : 1895
 
 karthik s wrote :1896
Hi Great.... example....
and one question .. If we give automative id increment the datas doesnt stored into db propery...

i got like ...

id name number
1  123
2  213

am getting like this.. hw can i do that