2016-06-15 3 views
0

삽입 검색에서 중복 데이터 건너 뛰기를위한 배열 검색 사용.배열 검색 PHP mysql PDO

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '053fb04a34907637530dcb86b9f121f5fe499821' for key 'id'"

$check=$this->pdo->prepare("select id from user_places"); 
$check->execute(); 
$a = $check->fetchAll(PDO::FETCH_COLUMN, 0); 

for ($i = 0; $i < count($output->results); $i++) { 
    if (array_search($data[$i]['id'], $a) == "") { 
     $query->bindparam(1,$data[$i]['id']); 
     $query->bindparam(2,$data[$i]['name']); 
     $query->bindparam(3,$data[$i]['lat']); 
     $query->bindparam(4,$data[$i]['lng']); 
     $query->bindparam(5,$data[$i]['place_id']); 
     $query->bindparam(6,$data[$i]['types']); 
     $query->bindparam(7,$data[$i]['vicinity']); 
     $query->execute(); 
    } 
} 

답변

0

From the manual for array_search : $data[$i]['id']가 배열 (인덱스 0, 즉 첫 번째 요소를 발견하면 당신은 진정한 평가합니다 array_search($data[$i]['id'], $a) == ""을 확인하고

Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

그러나 PDO의 오류가 발생합니다)

대신 다음을 사용해보세요.

if (array_search($data[$i]['id'], $a) === false) {