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