Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put booleans into a mysql database with prepared statements?

According to the PHP manual, the four variable types for mysqli->bind_param are

  1. integer,
  2. double,
  3. string and
  4. blob.

What is the best way to insert a boolean?

like image 915
fdsa Avatar asked Jun 24 '12 22:06

fdsa


People also ask

How do I add a Boolean value to a database?

You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.

How do you set a boolean to true in MySQL?

You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).

What is prepared statement in MySQL?

The PREPARE statement prepares a SQL statement and assigns it a name, stmt_name , by which to refer to the statement later. The prepared statement is executed with EXECUTE and released with DEALLOCATE PREPARE . For examples, see Section 13.5, “Prepared Statements”. Statement names are not case-sensitive.


1 Answers

MySQL doesn't really store booleans anyway, it's a trick.

The actual format is TINYINT, which is I guess integer for pdo.

You will have to convert true/false to 1/0, with intval for example.

like image 126
Sebas Avatar answered Nov 01 '22 12:11

Sebas