Hello Everyone

Iam Exporting All My Data From Mysql To Txt File With This Code

<?php
$sql2 = mysql_query("SELECT * FROM export
INTO OUTFILE '/Zero.txt' 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'");
?>

I Need To Edit The Code So It Export The New Data I Insert In MySql Only (( Not All Data Again ))

And Save It To A New File And Not In The Same File .

What defines 'new data' ?

Member Avatar for diafol

Have another field in export:
int(5?) called txtfile, default 0

When you're ready to create a new textfile:

$r = mysql_query("SELECT MAX('txtfile') + 1 AS nextval FROM export");
$d = mysql_fetch_assoc($r);
$nextval = $d['nextval'];

$r = mysql_query("SELECT * FROM export WHERE txtfile = 0 
INTO OUTFILE '/Zero_$nextval.txt' 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'");

$r = mysql_query("UPDATE export SET txtfile = $nextval WHERE txtfile = 0");

Note - no error checking or validation or anything else - it's very bare bones.
This has the advantage of storing the 'file label increment number', e.g. 4 in Zero_4.txt, 78 in Zero_78.txt, etc so that you've automatically indexed the record an the file.

commented: Thanks Sir So Much You Gave Me The Idea Iam Needing +2

New Data Mean The New Records I Added

And Thanks Diafol Iam Gonna Test Code And Tell U

Thanks Sir diafol So Much You Gave Me The Idea Iam Needing

Everything Is Ok Now

All I Need To Do Is One Thing

The New Records Come In A new Text File Instead of The Same File

INTO OUTFILE '/Zero_$nextval.txt'
Member Avatar for diafol

Er, does this mean it's solved? A new file is created each time?

Yeah Thanks Sir I Leaned Much Tips From Your Code

Solved

Member Avatar for diafol

OK, mark the thread solved - press the button/link below.

Done Thanks So Much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.