2012-04-25 7 views
0

私は同様の質問があることを知っている、私は(PHPのドキュメントを含む)それらの束を試してみましたが、私はこれを動作させるように見えません。mysqli multi_queryとinsert_idが私のコマンドを同期させません。

私は、次のを持っていない:

$query = "insert into page title values ('v1');insert into page title values ('v2');insert into page title values ('v3');" 

$mysqlidb->multi_query($query); 

$index = 0; 
$insertId = $this->db->insert_id; 
for($i = $insertId; $i < $insertId + sizeof($pages); $i++) { 
    //store ids in some array 
} 

私は上記のコードを実行すると、関係なく、私は私が得るデシベルに次に何をしようとするものは、「同期のOUT命令;あなたは今、このコマンドを実行することはできません"エラー。

私はすべての結果を閉じる必要があることを理解していますが、問題はどのようにわかりませんか。

$mysqli->more_results()がtrueを返しますが、use_result()またはstore_result()を呼び出すと結果が返ってきますが、これらはnullを返します。私は(前とnext_resultを呼び出した後ということをやってみました)、それは常にnullです:

while($mysqli->more_results()) { 
    //next line returns error, calling close() on null: 
    $mysqli->use_result()->close(); 
    $mysqli->next_result(); 
} 

または

while($mysqli->more_results()) { 
    $mysqli->next_result(); 
    //next line returns error, calling close() on null: 
    $mysqli->use_result()->close(); 

} 

同期はずれコマンド」を取り除くためにどのように、助けてください、あなたがすることができます」 multi_queryの挿入とinsert_idの呼び出しを行った後で、このコマンドをすぐに実行してください。ありがとう。

答えて

1
$values = ('v1' => '','v2' => '','v3' => ''); 
foreach ($values as $key => $val) { 
    $query = "insert into page title values ('$key')"; 
    $mysqlidb->query($query); 
    $values[$key] = $mysqlidb->insert_id; 
} 
+0

複数の(単一の)クエリでmulti_queryを置き換えても、パフォーマンスには影響しませんが、 –

+0

Nope。それはない –

+0

あなたは、私はあなたのソリューションを試してきた、私はこれを使用するつもりです。ありがとう。 –

関連する問題