这次作业比较迷,还在懵逼中
目前只改写了PDOModle.class.php文件,其他几个文件之间的逻辑关系还没搞清楚emmmmm
<?php//这里是PDOModle.class.php,大体是根据社长给的Modle.class.php改写的
namespace MyProject;
require_once ("iModel.php");
class PDOModel implements iModel
{
protected $connection;//储存一个POD对象
protected $sql;//储存sql语句
protected $exec_line;//储存exec函数执行所改变的行数
// your code
public function __construct($dbDsn, $dbUsername, $dbPassWord)
{
$this->connection = new \PDO($dbDsn, $dbUsername, $dbPassWord);
}
public function hasError()
{
return $this->connection->errorCode() ? true : false;
}
public function getError()
{
return $this->connection->errorCode();
}
public function sql()
{
return $this->connection->exec($this->sql);
}
public function update(string $statement)
{
$this->sql = $statement;
$this->exec_line = $this->sql();
if ($this->hasError()) {
return null;
}
echo "update" . $this->exec_line . "rows\n";
}
public function insert(string $statement)
{
$this->sql = $statement;
$this->exec_line = $this->sql();
if ($this->hasError()) {
return null;
}
echo "insert" . $this->exec_line . "rows\n";
}
public function delete(string $statement)
{
$this->sql = $statement;
$this->exec_line = $this->sql();
if ($this->hasError()) {
return null;
}
echo "delete" . $this->exec_line . "rows\n";
}
public function select(string $statement)
{
$this->sql = $statement;
$result = $this->connection->query($this->sql);
if ($this->hasError()) {
return null;
}
echo $result->fetch(\PDO::FETCH_ASSOC);
}
public function __destruct()
{
// TODO: Implement __destruct() method.
if ($this->connection)
$this->connection = NULL;
}
}
目前还未测试emmmm