Blogger Information
Blog 42
fans 3
comment 2
visits 93580
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP操作PDO实例
Whitney的博客
Original
2496 people have browsed it

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();
}
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post