php 如何更新 mysql 中的布尔值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7655423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:06:34  来源:igfitidea点击:

How can I update the boolean values in mysql?

phpmysql

提问by LifeOnCodes

My table has an isSuccessfulcolumn, I set the datatype as boolean (0 indicates false, 1 indicates true), and by default is 0.

我的表有一isSuccessful列,我将数据类型设置为布尔值(0 表示假,1 表示真),默认为 0。

But when I want to update this column using php,

但是当我想使用 php 更新此列时,

UPDATE .......... SET isSuccessful = 1 WHERE .........

it doesn't work.

它不起作用。

I tried to set the isSuccessfulas 1, true, yes, but none of them will work.

我试图将其设置isSuccessful为 1、true、yes,但它们都不起作用。

So how can I change the values of isSuccessful?

那么如何更改 的值isSuccessful呢?

回答by Ben Swinburne

A simple update query should suffice. Boolean fields are simply tinyint(1) fields and accept aliases for 1 and 0 as true and false respectively (as strings). The following should be fine. Perhaps if you posted your exact query rather than an abridged version someone might spot a problem?

一个简单的更新查询就足够了。布尔字段只是 tinyint(1) 字段,并分别接受 1 和 0 的别名为真和假(作为字符串)。以下应该没问题。也许如果您发布了您的确切查询而不是删节版本,有人可能会发现问题?

UPDATE `table` SET `isSuccessful` = 1 WHERE `column` = 'criteria'

回答by user979648

Make Sure you put this " ` " character which is same key of the " ~ " on the left size of "1" key on the keyboard, that should do it, if you using PHP+ Mysql Under linux.

确保你把这个与“~”键相同的“`”字符放在键盘上“1”键的左边大小,如果你在Linux下使用PHP+ Mysql,应该这样做。