mysqli_result::fetch_column
(mysqli_fetch_column) Fetch a single column from the next row of a result set
Function name: mysqli_result::fetch_column()
Applicable version: PHP 5 >= 5.3.0, PHP 7
Usage: The mysqli_result::fetch_column() function is used to get the value of a column from the result set. This function can only be used for SELECT query result sets executed using mysqli::query().
Example:
// 假设已经建立了数据库连接$conn // 执行SELECT 查询$query = "SELECT name FROM users"; $result = $conn->query($query); // 检查查询结果是否为空if ($result->num_rows > 0) { // 获取第一列的值$column = $result->fetch_column(); // 输出列的值echo "Column value: " . $column; } else { echo "No results found."; } // 释放结果集$result->close(); // 关闭数据库连接$conn->close();
Notes: