在php中使用dedupper

在php中使用dedupper,php,mysql,Php,Mysql,我正在使用php处理电话号码的重复数据,我有一个csv格式的文件,其中有一列数百万个电话号码,我的问题是,这是正确的方法吗?我尝试使用一个表,但随着表变大,它处理搜索的速度越慢。然后,如果不存在CREATETABLE,我尝试了这个方法,使用前3个数字将它们分开。。程序仍然在大约100k时停止执行。。任何意见都将不胜感激。。我没有其他地方可以添加功能或编辑此内容 使用一个表,使用准备好的语句,将数字列设置为唯一。然后sql server将缓存查询,您不必选择检查该号码是否存在,因为如果不唯一,插

我正在使用php处理电话号码的重复数据,我有一个csv格式的文件,其中有一列数百万个电话号码,我的问题是,这是正确的方法吗?我尝试使用一个表,但随着表变大,它处理搜索的速度越慢。然后,如果不存在CREATETABLE,我尝试了这个方法,使用前3个数字将它们分开。。程序仍然在大约100k时停止执行。。任何意见都将不胜感激。。我没有其他地方可以添加功能或编辑此内容


使用一个表,使用准备好的语句,将数字列设置为唯一。然后sql server将缓存查询,您不必选择检查该号码是否存在,因为如果不唯一,插入将失败谢谢您的输入,希望我能接受您的回答,我是新来的。。再次感谢你。
if(isset($_POST['upsubmit']))
{
    $dup = 0;
    $forchecknum = 0;
    $inserted = 0;
    $notvalidnum = 0;
    $file = $_FILES['file']['tmp_name']; 

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

    while(($fileop = fgetcsv($handle,1000, ",")) !== false) 
    {
            $fileorp[0] = str_replace('.', '', $fileop[0]);

            if(strlen($fileop[0]) == 10){

                $tablenum = substr($fileop[0], 0, 3);               

                if($forchecknum != $tablenum){ //skips create if table is already created
                    mysqli_query($dbc, "CREATE TABLE IF NOT EXISTS `$tablenum` (`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `phone_number` VARCHAR(15) NOT NULL, `label_comment` VARCHAR(10) NOT NULL)"); //query check if table exist, if not, create one                    
                    $forchecknum = $tablenum;

                    $checkdup = mysqli_query($dbc, "SELECT `phone_number` FROM `$tablenum` WHERE phone_number='$fileop[0]' LIMIT 1");       
                    if(mysqli_num_rows($checkdup) > 0){
                        $dup++;
                    } else {

                    mysqli_query($dbc, "INSERT INTO `tmp_unique_numbers` (`id`, `phone_number`, `label_comment`) VALUES (NULL, '$fileop[0]', 'tmp');");
                    $inserted++;
                    //insert records
                    }

                }else{

                    $checkdup = mysqli_query($dbc, "SELECT `phone_number` FROM `$tablenum` WHERE phone_number='$fileop[0]' LIMIT 1");       
                    if(mysqli_num_rows($checkdup) > 0){
                        $dup++;
                    } else {

                    mysqli_query($dbc, "INSERT INTO `tmp_unique_numbers` (`id`, `phone_number`, `label_comment`) VALUES (NULL, '$fileop[0]', 'tmp');");
                    $inserted++;
                    //insert records
                    }                   
                }

            } else {

                    $notvalidnum++;
                    mysqli_query($dbc, "CREATE TABLE IF NOT EXISTS `tmp_not_valid_numbers` (`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `phone_number` VARCHAR(15) NOT NULL, `label_comment` VARCHAR(10) NOT NULL)"); //query check if table exist, if not, create one
                    mysqli_query($dbc, "INSERT INTO `tmp_not_valid_numbers` (`id`, `phone_number`, `label_comment`) VALUES (NULL, '$fileop[0]', '');");                 
            }

            fclose($handle);            
        }



}