Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
他不工作有人可以帮忙吗?
(count($stmt->fetchAll()) > 1) ? $result = $stmt->fetchAll() : $result = $stmt->fetch(); print_r($result);
所有fetchXYZ方法都会推进底层游标,因此一旦调用它们,就不能“返回”并再次获取相同的行。
fetchXYZ
fetchAll()只调用一次后,您可以在内存中重做您的条件:
fetchAll()
$result = $statement->fetchAll(); if (count($result) == 1) { $result = $result[0]; }