複数の mysql_query 呼び出しを使用して 1 つの mysqli_ を使用するコードを書き直そうとしていますが、動作させることができません。同じ場所で mysql_query ステートメントを mysqli_query ステートメントに単純に置き換えると、「コマンドが同期されていません。現在、このコマンドを実行できません」というメッセージが表示されます。
代わりに、すべてのクエリを mysqli_multi_query に取り込もうとすると、「通知: 未定義の変数: activeUser in /home/almostes/public_html/addrUpdate-proc-multi.php 14 行目」エラーが発生します。
一言で言えば、これは私が持っていたものです
// すべてのアクティブ ユーザーのリストを取得します
SELECT entity_id FROM customer_entity_int WHERE attribute_id = 153 and value = 1 ORDER BY entity_id
// この entity_id チェックのリストを循環して、このユーザーに対してアドレスが保存されているかどうかを確認します
SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;
// このユーザーに対して住所が保存されていない場合、customer_entity_varchar に保存されている情報を取得します
SELECT * FROM customer_entity_varchar WHERE entity_id = $entity_id;
// そして、これを適切なアドレス テーブルに入力します
INSERT INTO customer_address_entity VALUES (blah, blah, blah);
これを次のようなものに置き換える必要があると思います
$query = "SELECT entity_id FROM customer_entity_int WHERE attribute_id = 153 and value = 1 ORDER BY entity_id;"; # get list of all active users#
$query .= "SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;"; # is there an address stored against this name
$query .= "SELECT * FROM customer_entity_varchar WHERE entity_id = $entity_id;"; # get the info stored in customer_entity_varchar
$query .= "INSERT INTO customer_address_entity VALUES (blah, blah, blah);"
$result = mysqli_multi_query($mysqli, $query);
/* execute multi query */
if ($result) {
do {
/* store first result set */
if ($result = mysqli_store_result($mysqli)) {
while ($row = mysqli_fetch_assoc($result)) {
$entity_id = $row['entity_id'];
echo "<br />active user = $entity_id<br />";
}
mysqli_free_result($result);
}
/* print divider */
if (mysqli_more_results($mysqli)) {
printf("-----------------\n");
}
if (($result = mysqli_num_rows($mysqli)) < 1) // if no address stored against this user retrieve the registration data and enter into address data fields
{
echo '<br />yes<br />';
}
} while(mysqli_more_results($mysqli) && mysqli_next_result($mysqli));
}
しかし a) これにより、「Notice: Undefined variable: activeUser in /home/almostes/public_html/addrUpdate-proc-multi.php on line 14」エラーが発生し、14 行目は「$query .=」SELECT * FROM customer_address_entity WHERE parent_id = $entity_id;";"
そして、エコーされた出力を提供します
"アクティブ ユーザー = 5
アクティブ ユーザー = 6
アクティブ ユーザー = 78 インチ
b) アドレス情報なしでユーザーを取得し、目的のフィールドを取得するために、さまざまな SQL クエリを移動する構文がわかりません。
どんな助けでも大歓迎です。どうもありがとう