PHP操作PDO实例
实例
<?php $dsn = 'mysql:host=localhost;dbname=test'; $user = 'root'; $pwd = 'root'; $status = 1; try{ $sql = 'select * from user where status =: status'; $dbh = new PDO($dsn,$user,$pwd); $dbh->setAttribute(PDO:ATTR_ERRMODE,PDO_ERRMODE_EXCEPTION); $stmt->bindParam(':status',$status); $stmt->execute(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ echo $row['id']."\t".$row['status']."</br>"; } }catch(PDOException $e){ echo 'SQL QUERY'.$sql."</br>"; echo 'Connect failed:'.$e->getMessage(); } ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例