Hi guys,
I have a text file of usernames and password (one combination per line), a copy of which I am storing in a MYSQL database.
When my code executes the MYSQL database should be updated with an exact copy of the text file with any U/P combinations removed from the text file also removed from the database, and any new ones also added to the databse along with a time stamp.
The ordering is not important so no sorting is required, the two (text file and DB) simply must be identical. I'd appreciate any advice on the most efficient way of achieving this. How should I compare the text file and database? For example. should I copy both into an array first. Or should I simply read a line from the text file at a time and sequentially search the database row by row. Although this would appear to be the most obvious solution it is also probably the least efficient?
Your feedback would be much appreciated.
Many thanks,
Rob.
Efficiency of duplicate copy
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
You may try another approach - instead of comparing, you catch the process which modifies the file and apply the changes immediately to the database.
I think it is the right way - it is done in real time and much faster.
I think it is the right way - it is done in real time and much faster.
There are 10 types of people in this world, those who understand binary and those who don't
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Thanks for the replies.
I have decided to go with the array_diff function.
However I am experiencing some odd behaviour when comparing the two array as you can see if you check this link:
http://www.rebekahdee.com/index2.php
As you can see it appears as if the 2 arrays are identical but the result of the comparison suggests otherwise.
Array 1 is copied from a text file and if you highlight the 3 lines of text under "Array 1" as looks as if a whitespace character is/has been apended to the end of the string. To counter this I have tried stripping the whitespaces as follows:
Any ideas how I can get around this as I just have no idea.
Many thanks in advance,
Rob.
I have decided to go with the array_diff function.
However I am experiencing some odd behaviour when comparing the two array as you can see if you check this link:
http://www.rebekahdee.com/index2.php
As you can see it appears as if the 2 arrays are identical but the result of the comparison suggests otherwise.
Array 1 is copied from a text file and if you highlight the 3 lines of text under "Array 1" as looks as if a whitespace character is/has been apended to the end of the string. To counter this I have tried stripping the whitespaces as follows:
Code: Select all
while (!feof($handle)){
$file_array[$id]=fgets($handle);
$file_array[$id]=trim($file_array[$id]," ");
print_r($file_array[$id]);
echo"<br>";
$id++;
}Many thanks in advance,
Rob.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Hi,
I found that this removed the offending character(s):
Thanks,
Rob.
I found that this removed the offending character(s):
Code: Select all
$file_array[$id]=trim($temp, "\x00..\x1F");Rob.