PHP MYSQL

VERY SIMPLE CONTENT MANAGEMENT SYSTEM

(quick guide & example)

id title text

CONTENTS TABLE

01

INTEGER, PRIMARY KEY VARCHAR TEXT

<form method="post">   CONTENT ID   <input type="hidden" name="id">   TITLE   <input type="text" name="title">   TEXT   <textarea name="txt"></textarea>   <input type="submit" value="Save"> </form>

SAVE CONTENTS (A)

02

CONNECT TO DATABASE $pdo = new PDO("mysql:host=HOST; dbname=NAME;charset=utf8", USER, PASSWORD);

SAVE CONTENTS (B)

03

REPLACE SQL $stmt = $pdo->prepare("REPLACE INTO `contents` (`id`, `title`, `text`) VALUES (?,?,?)");

EXECUTE SQL $stmt->execute([$_POST["id"], $_POST["title"], $_POST["txt"]);

LOAD CONTENTS (A)

04

CONNECT TO DATABASE $pdo = new PDO("mysql:host=HOST; dbname=NAME;charset=utf8", USER, PASSWORD);

FETCH $id = 123; $stmt->execute([$id]); $content = $stmt->fetch();

SELECT SQL $stmt = $pdo->prepare("SELECT * FROM `contents` WHERE `id`=?");

<h1>   <?=$content["title"]?> </h1> <p>     <?=$content["text"]?>  </p>

LOAD CONTENTS (B)

05