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