我正在寻找一个
PHP PDO完整的工作示例,具有运行查询和处理错误的最佳做法.这是我到目前为止.
原文链接:/php/131608.html正在连接.如果您不这样做,连接失败将默认将DB凭据显示给您网站的所有用户.
try { $dbh = new PDO("MysqL:host=localhost;dbname=phor_lang","phor_lang","'9lsnthsn9"); } catch (PDOException $e) { error(false,"PDO ERROR: " . $e->getMessage()); }
用查询
$stmt = $dbh->prepare("INSERT INTO sets"); $stmt->execute() or error(0,"USERS ERROR ".__LINE__." ".print_r($dbh->errorInfo(),true)); $setID = $dbh->lastInsertID(); $stmt->closeCursor(); $stmt = $dbh->prepare("INSERT INTO words (language,name,detail,user,type,set) VALUES (?,?,?)"); $stmt->execute(array($l1l,$l1w,$l1d,$userID,'training',$setID)) or error(0,true)); $stmt->closeCursor();