Findall And Reading Files

Hi everyone,

I have a database of around 6,000 emails, the model is called NewsLetter. I also have a text file with around 1,400 emails written line by line with no space like so; 


These emails are taken from my database because they are not valid, I extracted all emails that do not send. What I want to do is read the text file emails and match with my DB emails so I can delete them. This is what I have

$handle = fopen("", "r");

if ($handle) {

    while (($line = fgets($handle)) !== false) {

    $line = (string)$line;

	$token  = explode("\n", $line);

	$n = NewsLetter::model()->findAll('Email = :Email', array(':Email' => $line));

	foreach ($n as $y){

	echo $y->Email."<br />";

This doesn’t work, it just loads slowly and displays nothing, the file is being read because echo $line works perfectly. I know the emails match because if I manually type an email into findAll it matches. Can anyone tell me why this doesn’t work and how to?


$emails = file("", FILE_IGNORE_NEW_LINES);

NewsLetter::model()->deleteAllByAttributes(array('Email' => $emails));

Maybe you should try:

$line = trim($line);

I cannot think of anything else to explain why it would not work.

Oh, wait, maybe you should try this:

$n = NewsLetter::model()->findAll("Email = ':Email'", array(':Email' => $line));

Thanks for the reply guys, unfortunately none of your suggestions work.

Nevermind guys, turns out whitespaces where causing all the issues, specially from the DB. So this solved it

$n = NewsLetter::model()->findAll('LTRIM(RTRIM(Email))  = :Email', array(':Email' => trim($line)));