这是我的PDO课程
<?php
class Database
{
protected $dbh;
protected $query;
public $rows;
public function __construct($host,$user,$pass,$dbname)
{
// Set DSN
$dsn = 'mysql:host=' . $host . ';dbname=' . $dbname;
// Set options
$options = array( PDO::ATTR_PERSISTENT=> true,
PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION);
// Create a new PDO instanace
try
{
$this->dbh = new PDO($dsn, $user, $pass, $options);
}
catch(PDOException $e)
{
echo $this->error = $e->getMessage();
die();
}
}
public function query($query)
{
$this->query = $this->dbh->query($query);
}
public function execute($array=null)
{
$this->stmt->execute($array);
}
public function fetchAllQuery()//--------------------(1)
{
$resultQuery = $this->query->fetchAll(PDO::FETCH_ASSOC);
$this->rows = count($resultQuery);
return $resultQuery;
}
public function fetchQuery()//------------(2)
{
return $this->query->fetch(PDO::FETCH_ASSOC);
}
public function rowCountQuery()///////////////
{
return $this->rows;
}
}
$database = new Database('localhost','root','','speed');
$query = $database->query("SELECT * FROM tbl_deliverygrid");
$result = $database->fetchAllQuery();//--------------calling method (1)
echo '<pre>',print_r($result),'</pre><br>';
while($result2 = $database->fetchQuery())//----------calling method (2)
{
echo $result2['area'];
echo '<br>';
}
如何同时使用(1)和(2)方法获得结果?