WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 21 times)
Viewed : 31353
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

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

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
?>



usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
This class splits the results of the query into multiple pages like what the search engine does.
Categories : PHP Classes, PHP, MySQL, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
 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