Correction status:Uncorrected
Teacher's comments:
<?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忘了
点击 "运行实例" 按钮查看在线实例