2012-08-14 2 views
2

나는 현재하고있는 중이 야 다음에 다음mysqli multi_query 쿼리

$mysqli = new mysqli($server, $username, $password, $database); 

$mysqli->multi_query($multiUpdates); 
while ($mysqli->next_result()) {;} // Flushing results of multi_queries 
$mysqli->query($sqlInserts); 

결과를 덤프 빠른 방법이 있나요?

내가 그들을 필요로하고 바로 다음 쿼리를 실행하지 않으 그러나 나는 오류를 얻을 :

Commands out of sync; you can't run this command now

문제가 while ($mysqli->next_result()) {;}입니다 내가 원하지 않는 무언가 낭비 약 2 초 정도 걸립니다.

더 나은 해결책이 있습니까?

+0

http://stackoverflow.com/questions/22531943/speed-best-practice-flushing-mysqli-multi-query –

답변

3

500 개의 레코드를 업데이트하고 500 개의 레코드를 삽입 할 때 약 2 ~ 3 초를 단축하는 더 빠른 솔루션을 발견했습니다.

function newSQL() { 
    global $server, $username, $password, $database; 
    $con = new mysqli($server, $username, $password, $database); 
    return $con; 
} 

$mysqli = newSQL(); 
$mysqli->multi_query($multiUpdates); 
$mysqli->close(); 

$mysqli = newSQL(); 
$mysqli->query($sqlInserts); 
$mysqli->close(); 

속도가 얼마나 잘 작동하는지는 잘 모르지만 속도는 좋아집니다.