将1行1字段的查询直接保存到变量中,而不是使用while循环


Save a 1 row, 1 field query directly into a variable instead of using while loop

如果您有类似的查询

SELECT max(customerID) FROM customers

有没有一种方法可以直接将其保存到变量中,而不是使用

$results = $dbLink->query("SELECT max(customerID) FROM customers");
while($row = $results->fetch_assoc()){
    $maxID = $row['customerID'];
}

后者只是1值的很多类型

这很简单-只是不要使用循环:

$results = $dbLink->query("SELECT max(customerID) FROM customers");
$row = $results->fetch_assoc();
$maxID = $row['customerID'];