通过pdo来从数据库中调取数据。
其中主要涉及到 pdo fetch,pdo fetchAll,pdo query,pdo prepare使用 。
可以通过以下几种方式,学习下php pdo的用法。
第一、
 
第二种、
 
try{
 $db = new PDO($dbconn['dns'],$dbconn['dbuser'],$dbconn['dbpwd']);
 $db->query("set names utf8");
 $sql = "SELECT * FROM wp_posts limit 2";
 $query = $db->query($sql);
 $result = $query->fetchAll();
 print_r($result);
}catch(PDOException  $e)
{
 echo $e->getMessage();
}
 
第三种,
 
try{
 $db = new PDO($dbconn['dns'],$dbconn['dbuser'],$dbconn['dbpwd']);
 $db->query("set names utf8");
 $sql = "SELECT * FROM wp_posts limit 2";
 $query = $db->query($sql);
 $result = $query->fetch();
 foreach($query as $rs)
 {
  print_r($rs);
 }
}catch(PDOException  $e)
{
 echo $e->getMessage();
}
 
第四种,
 
try{
 $db = new PDO($dbconn['dns'],$dbconn['dbuser'],$dbconn['dbpwd']);
 $db->query("set names utf8");
 $sql = "SELECT * FROM wp_posts where ID = :id ";
 $sth = $db->prepare($sql);
 $sth->execute(array(':id'=>'12'));
 $rs = $sth->fetchAll();
 print_r($rs);
}catch(PDOException  $e)
{
 echo $e->getMessage();
}
 
pdo fetch,pdo fetchAll,pdo query,pdo prepare使用 基本的就这些。
更多详细的信息,去查 php手册吧。