我的查询是:
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,布尔值在C:\Program Files (x86)\EasyPHP-12.1\www\App\php\post\excel_yukle.php第123行
警告:mysqli_error() 需要 1 个参数,0在第124行的C:\Program Files (x86)\EasyPHP-12.1\www\App\php\post\excel_yukle.php中给出
编辑:我试过这个:
/* 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 />