Mysql多选查询

时间:2017-01-19 15:32:42

标签: php mysql pdo multiple-select

我有600.000个数据,我把这些值拉紧了。 我在数据库中压缩了一些值。关于应变数据我有10个标准。 所以,当我从10个标准中压缩600.000数据时,我的mysql服务器非常慢。我怎样才能让它快速?这是我关于应变的源代码。

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
ini_set('memory_limit', '256M');
function Check($Value,$DataBase)
{

    $QueryString = "SELECT UserID FROM users where ".$Value;
    $query = $DataBase->query($QueryString, PDO::FETCH_ASSOC);
    //echo $Sorgu;
    if ($query->rowCount()) {
        foreach ($query as $row) {
            return true;
        }
    }
    return false;
}

$Array = $_POST["Data"];
$Array = json_decode($Array, true);

$Keys = ' ';
$Values = ' ';
$GSM1 = array();
$GSM2 = array();
$Phone1 = array();
$Phone2 = array();
$Fax1 = array();
$Fax2= array();
$UserCode = array();
$Identitiy = array();
$Empty = array();
$EmptyCheck = true;
foreach ($Array as $Row) {
    $EmptyCheck = true;
    $Keys = ' ';
    $Values = ' ';
    foreach ($Row as $key => $val) {


        if ($key == 'UserGsm1') {
            if ($val != null AND is_numeric($val) AND Check('UserGsm1=' . $val,$db)) {
                $EmptyCheck = false;
                $Gsm1[] = $Row;
                break;
            }
        } else if ($key == 'UserGsm2') {
            if ($val != null AND is_numeric($val) AND Check('UserGsm2=' . $val,$db)) {
                $EmptyCheck = false;
                $Gsm2[] = $Row;
                break;
            }
        } else if ($key == 'UserPhone1') {
            if ($val != null AND is_numeric($val) AND Check('UserPhone1=' . $val,$db)) {
                $EmptyCheck = false;
                $Phone1[] = $Row;
                break;
            }
        } else if ($key == 'UserPhone2') {
            if ($val != null AND is_numeric($val) AND Check('UserPhone2=' . $val,$db)) {
                $EmptyCheck = false;
                $Phone2[] = $Row;
                break;
            }
        } else if ($key == 'UserFax1') {
            if ($val != null AND is_numeric($val) AND Check('UserFax1=' . $val,$db)) {
                $EmptyCheck = false;
                $Fax1[] = $Row;
                break;
            }
        } else if ($key == 'UserFax2') {
            if ($val != null AND is_numeric($val) AND Check('UserFax2=' . $val,$db)) {
                $EmptyCheck = false;
                $Fax2[] = $Row;
                break;
            }
        } else if ($key == 'UserCode') {
            if ($val != null AND is_numeric($val) AND Check('UserCode=' . $val,$db)) {
                $EmptyCheck = false;
                $UserCode[] = $Row;
                break;
            }
        } else if ($key == 'UserIdentitiy') {
            if ($val != null AND is_numeric($val) AND Check('UserIdentitiy=' . $val,$db)) {
                $EmptyCheck = false;
                $Identitiy[] = $Row;
                break;
            }
        }
        $Keys = $Keys . ',' . $key;
        $Values = $Values . ',' . $val;
        //echo $key.' : '.$val;
        //echo '<br>';
    }
    if ($EmptyCheck == true) {
        $Empty[] = $Row;
    }


}

0 个答案:

没有答案