This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# MySQL connection | |
$mysql = mysqli_connect("db", "root", "example"); | |
# DDL | |
$mysql->query("CREATE DATABASE IF NOT EXISTS demo;"); | |
$mysql->query("USE demo;"); | |
$mysql->query("CREATE TABLE IF NOT EXISTS todos(tid INT PRIMARY KEY AUTO_INCREMENT, is_checked BOOLEAN, message TEXT);"); | |
# Prepared Statements | |
$newStmt = $mysql->prepare("INSERT INTO todos(is_checked, message) VALUES (false, ?);"); | |
$checkStmt = $mysql->prepare("UPDATE todos SET is_checked = !is_checked WHERE tid = ?;"); |