PHP MYSQL

STORE & RETRIEVE HTML CODE IN PHP MYSQL

(a simple example)

CONTENTS DATABASE TABLE

01

id | BIGINT(20) PRIMARY KEY contents | TEXT

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

STORE HTML CODE

02

SAVE HTML INTO TABLE $stmt = $pdo->prepare("INSERT INTO `web_contents` (`contents`) VALUES (?)"); $stmt->execute(["<p>FOO<p>"]);

RETRIEVE HTML CODE

03

GET HTML CODE FROM DATABASE $stmt = $pdo->prepare("SELECT `content` FROM `web_contents` WHERE `id`=?"); $stmt->execute([123]); $html = $stmt->fetchColumn();

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