我想选择一行 Ad 作为 bool 值,这是严格正确的。 我正在使用以下 SQL 语句。
SELECT 'user' AS username, 'pass' AS password, true AS Ad FROM users LIMIT 1;
然而,上述语句选择 Ad 为 1,且不为 true,因此不满足以下条件。 ===。更改下面的代码不是一个选项。
if($row["Ad"] === true){
echo("<h1>You are the admin</h1>");
}
最佳答案
MySQL 实际上没有boolean
类型。相反,它将 true
表示为 1
,将 false
表示为 0
,并且使用类型 TINYINT
为此目的。
如果您想返回true
,则必须使用文本值:
SELECT
'user' AS username,
'pass' AS password,
'true' AS Ad
FROM users
LIMIT 1
然后:
if($row["Ad"] === "true") {
关于php - sql - 选择 bool 值严格为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38500620/