Don't use a separate query to get min/max product IDs. Use a JOIN
with the product
table in an INSERT ... SELECT
.
$stmt = $con->prepare('
INSERT INTO review (product_id, author, text)
SELECT product_id, ?, ?
FROM product
WHERE status = 1
ORDER BY RAND()
LIMIT 1');
$stmt->bind_param("ss", $data["name"], $data["commentary"]);
Then call $stmt->execute()
in the insert loop.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…