php-mysqlHow to store a boolean value in a MySQL database using PHP?
MySQL databases can store boolean values using the TINYINT data type. This data type can store values of 0 (false) or 1 (true). To store a boolean value in a MySQL database using PHP, the following code can be used:
$boolean_value = true;
$sql = "INSERT INTO table_name (boolean_column) VALUES (?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $boolean_value);
$stmt->execute();
The code above:
- Declares a variable
$boolean_valueand assigns it a boolean value oftrue. - Creates an SQL query to insert a value into a table.
- Prepares the SQL query for execution.
- Binds the boolean value to the SQL query.
- Executes the SQL query.
Helpful links
More of Php Mysql
- How to output XML from MySQL using PHP?
- How to get the version of MySQL using PHP?
- Inserting data to MySQL using PHP
- How to write an update query in MySQL using PHP?
- How to use a MySQL union in PHP?
- How to set a timeout for MySQL query in PHP?
- How to export data from MySQL to Excel using PHP?
- How to get the last insert ID in PHP MySQL?
- How to create an SSL connection to MySQL using PHP?
- How to list tables in PHP MySQL?
See more codes...