1

私のクエリは次のとおりです。

CREATE TEMPORARY TABLE `hcaconsumptions_temp` (
    `DeviceID` INT (11) NOT NULL,
    `TimeStamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `Consumption` FLOAT NOT NULL,
    `DeviceBrand` VARCHAR (255) CHARACTER
SET utf8 COLLATE utf8_unicode_ci NOT NULL,
 `SerialNumber` VARCHAR (255) CHARACTER
SET utf8 COLLATE utf8_unicode_ci NOT NULL
) ENGINE = MyISAM DEFAULT CHARACTER
SET = utf8 COLLATE = utf8_unicode_ci;

INSERT INTO hcaconsumptions_temp 
    (DeviceBrand, SerialNumber, `TIMESTAMP`, Consumption) 
    VALUES
    ('Adunos','24100008','2013-01-14 19:39:48','157'),
    ('Adunos','24100010','2013-01-14 18:50:38','134'),
    ...
    ('Adunos','24100019','2013-01-14 18:40:58','117'),
    ('Adunos','24100020','2013-01-14 18:42:22','74');

UPDATE hcaconsumptions_temp
SET DeviceID = (
    SELECT
        DeviceID
    FROM
        hcadevices
    WHERE
        hcadevices.DeviceBrand = hcaconsumptions_temp.DeviceBrand
    AND hcadevices.SerialNumber = hcaconsumptions_temp.SerialNumber
);

SELECT
    count(DeviceID)
FROM
    hcaconsumptions_temp
WHERE
    DeviceID = '0';

最後にご覧のとおり、SELECTクエリがありますが、結果を取得できません。

おそらく、前に 3 つのクエリがあるため、エラーが発生します。どうすれば結果を取得できますか?

私のPHPコードは次のとおりです。

$test_result = mysqli_multi_query($link, $multi_test_query);
$count = mysqli_fetch_assoc($test_result);
print_r($count);

与えられる警告は次のとおりです。

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given

このコードでは 2 つのエラーが発生します。

$test_result = mysqli_multi_query($link, $multi_test_query);
$count = mysqli_fetch_assoc($test_result);
echo mysqli_error();
print_r($count);

警告: mysqli_fetch_assoc() は、パラメーター 1 が mysqli_result であると想定します。これは、123行目のC:\Program Files (x86)\EasyPHP-12.1\www\App\php\post\excel_yukle.phpで指定されたブール値です。

警告: mysqli_error() は正確に 1 つのパラメーターを予期します。0 はC:\Program Files (x86)\EasyPHP-12.1\www\App\php\post\excel_yukle.php124で指定されます

編集:私はこれを試しました:

/* execute multi query */
if (mysqli_multi_query($link, $multi_test_query)) {
    do {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_row($result)) {
                printf("%s\n", $row[0]);
            }
            mysqli_free_result($result);
        }
        /* print divider */
        if (mysqli_more_results($link)) {
            printf("-----------------\n");
        }
    } while (mysqli_next_result($link));
}

結果は次のとおりです。

-----------------
-----------------
-----------------
46
<br />
<b>Strict Standards</b>:  mysqli_next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method in <b>C:\Program Files (x86)\EasyPHP-12.1\www\HCAWebApp\php\post\excel_yukle.php</b> on line <b>136</b><br />
4

2 に答える 2

0

私はそれを解決しました。

$i = 1;
if (mysqli_multi_query($link, $multi_test_query)) {
    while(mysqli_next_result($link)) {
        /* store first result set */
        if ($result = mysqli_store_result($link)) {
            while ($row = mysqli_fetch_row($result)) {
                //printf("%s\n", $row[0]);
                if($i==3) $satirsayisi = $row[0];
            }
            mysqli_free_result($result);
        }
        /* print divider */
        if (mysqli_more_results($link)) {
            //printf("-----------------\n");
        }

        $i = $i + 1;
        if($i>3) break;
    }
}


echo $satirsayisi;
于 2013-02-15T16:55:01.063 に答える