|
|
|
|
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 | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP, PHP Classes, Databases, MySQL, Navigation | | | PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | MySQL Class to ease Database connectivity Categories : MySQL, PHP Classes, Databases, PHP | | | Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | Online Automatic Class Generator for MySQL Tables Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Convert a File database into MySQL Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides | | | Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Simple usersOnline class - keep track of how many users are online on your site Categories : PHP, PHP Classes, Databases, MySQL | | | Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP. Categories : PHP Classes, Databases, PHP, MySQL, InnoDB | | | YellowPages Content Grabber (PHP5 +) Categories : PHP, PHP Classes, Regexps, Databases, MySQL | | | Ajax PHP Tree (Left and Right) with MySQL Categories : PHP, Databases, MySQL, AJAX, PHP Classes | |
|
|
|