Blogger Information
Blog 61
fans 1
comment 0
visits 69755
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0619-用命名空间写sql查询
我的博客
Original
684 people have browsed it

实例

<?php

namespace sql;
use PDO;

class Db{
 protected  $pdo = null;

 public function __construct()
 {
     $this->pdo =new PDO('mysql::host=127.0.0.1;dbname=php','root','root');
    //var_dump($this->pdo);
 }
public function select($table,$fields,$where){
$sql = 'SELECT '. $fields .' FROM '. $table .' WHERE ' . $where;
    
$stmt=$this->pdo->prepare($sql);
$stmt->execute();
//$stmt->debugDumpParams();
return $stmt->fetchAll(PDO::FETCH_ASSOC);

}
}
$sql = new Db();
echo  '<pre>'. print_r($sql->select('staff','name','staff_id>1'),true) ;  //这里echo print_r忘了

运行实例 »

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


Correction status:Uncorrected

Teacher's comments:
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