0

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 .

Edited by -==Zero==-

3
Contributors
9
Replies
10
Views
5 Years
Discussion Span
Last Post by -==Zero==-
1

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.

Votes + Comments
Thanks Sir So Much You Gave Me The Idea Iam Needing
0

New Data Mean The New Records I Added

And Thanks Diafol Iam Gonna Test Code And Tell U

0

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'

Edited by -==Zero==-

0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.