PDO::CASE_LOWER, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, ); //-------------------------------------------------- // Connect Database //-------------------------------------------------- try { $dbh = new PDO(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWD, $PDO_OPTIONS); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh -> exec('SET NAMES utf8'); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } /******************************************************************************************************** $id = 123; $name = 'Chan Tai Man'; $pwd = md5(123456); $date = '20130101'; ### Delete SQL ### $sth = $dbh->prepare('DELETE FROM `user` where id = ?'); $sth->bindParam(1, $id); $sth->execute(); ### Insert SQL ### $sth = $dbh->prepare('INSERT INTO `user`(`id`, `name`, `pwd`, `date`) VALUES (?,?,?,?)'); $sth->bindParam(1, $id); $sth->bindParam(2, $name); $sth->bindParam(3, $pwd); $sth->bindParam(4, $date); $sth->execute(); ### Select SQL ### $sth = $dbh->prepare('SELECT * FROM `user` where id = ?'); $sth->bindParam(1, $id); $sth->execute(); while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { echo 'name : ' . $ResultSet['name'] . '
'; echo 'id : ' . $ResultSet['id'] . '
'; echo 'pwd : ' . $ResultSet['pwd'] . '
'; echo 'date : ' . $ResultSet['date']; } ### Error Checking ### if ($sth->errorCode()) print_r($sth->errorInfo()); ********************************************************************************************************/ ?>