来自PDO 标签维基:
<?php
// connect. have to be moved into separate file to be included
$dsn = "mysql:host=localhost;dbname=test;charset=utf8";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn,'root','', $opt);
//getting data
$id = 20;
$stm = $pdo->prepare("SELECT text FROM about WHERE id=?");
$stm->execute(array($id));
$text = $stm->fetchColumn();
//echoing out
?>
<form method="post">
<textarea id="styled" name="content"><?=htmlspecialchars($text)?></textarea>
<br/>
<input type="submit" name="Update">
</form>