【发布时间】:2011-08-19 14:32:04
【问题描述】:
这是我在php中的类数据库
<?php
class DB
{
private $SQLcommand;
private $bd;
public function setSQLcommand($valor)
{
$this->SQLcommand = $valor;
}
public function getSQLcommand()
{
return($this->SQLcommand);
}
function __construct()
{
$this->bd = new PDO("mysql:host=localhost;dbname=cpd", "root", "");
}
public function ExecSQL()
{
if ($this->SQLcommand != "")
return($this->bd->exec($this->SQLcommand));
else
return(false);
}
public function ExecSelect()
{
if ($this->SQLcommand != "")
{
$data = $this->bd->query($this->SQLcommand);
return($data->fetchAll());
}
else
return(false);
}
function __destruct()
{
$this->bd = null;
}
}
?>
这是我实例化的方式
include_once 'db_class.php';
$e = new DB();
$e->setSQLcommand("INSERT INTO characteristic (id_charac,name_charac)
VALUES ('','".$_POST["nomecharac"]."')");
$e->ExecSQL();
$p = new DB();
$p->setSQLcommand("select * from characteristic");
$data = $p->ExecSelect();
我会问我可以在代码中的哪里放置一个try catch,如果发生错误,try catch 会重定向到文件maintenance.php,并防止显示银行的用户名和密码...谢谢大家。 ..
【问题讨论】: