Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update the boolean values in mysql? [closed]

Tags:

php

mysql

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

But when I want to update this column using php,

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

it doesn't work.

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

So how can I change the values of isSuccessful?

like image 892
LifeOnCodes Avatar asked Oct 05 '11 00:10

LifeOnCodes


People also ask

How do I update a field value in MySQL?

MySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.

Can you store boolean in MySQL?

MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.

How do I select a boolean in MySQL?

MySQL does not contain built-in Boolean or Bool data type. They provide a TINYINT data type instead of Boolean or Bool data types. MySQL considered value zero as false and non-zero value as true. If you want to use Boolean literals, use true or false that always evaluates to 0 and 1 value.


1 Answers

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?

UPDATE `table` SET `isSuccessful` = 1 WHERE `column` = 'criteria'
like image 147
Ben Swinburne Avatar answered Oct 13 '22 22:10

Ben Swinburne