データベースへの接続
try { $dbh = new PDO('mysql:host=localhost;dbname=blog_app','dbuser001','dbpwd0001'); } catch (PDOException $e) { var_dump($e->getMessage()); exit; }
データベースへの接続解除
$dbh = null;
データベースへのデータ挿入
$stmt = $dbh->prepare("insert into users (name,email,password) values (?,?,?)"); $stmt->execute(array("n","e","p"));
prepareとやると、エスケープ処理もしてくれる。