function getPP($Proname1)
{
$result = null;
$sql= "SELECT SUM(num) AS num FROM pro1 WHERE proname =?";
$sth = $this->dbh->prepare($sql);
$sth->bindValue(1,$Proname1,PDO::PARAM_STR);
//查询数据库
//执行预处理语句,并将结果保存在$sth中
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);//只返回关联索引
// 显式的关闭PDO连接
$this->dbh = NULL;
// [03]返回结果
return $result;
}function insPP1($ID,$PRO,$PRI,$NUM,$TOT,$DES)
{
$result = false;
$a=$this->getPP($PRO);
$PTO=($a['num']-$NUM);
$sql = "INSERT INTO pro(id,proname,price,num,total,description,inv) VALUES (?,?,?,?,?,?,?)";
try{
$sth = $this->dbh->prepare($sql);
// 准备预处理语句
$sth->bindValue(1, $ID, PDO::PARAM_INT);
$sth->bindValue(2, $PRO, PDO::PARAM_STR);
$sth->bindValue(3, $PRI, PDO::PARAM_STR);
$sth->bindValue(4, $NUM, PDO::PARAM_INT);
$sth->bindValue(5, $TOT, PDO::PARAM_STR);
$sth->bindValue(6, $DES, PDO::PARAM_STR);
$sth->bindValue(7, $PTO, PDO::PARAM_INT);
$result = $sth->execute();
// 执行插入操作并将是否成功的结果保存在一个变量中
$this->dbh = NULL;
$result = true;
} catch (PDOException $err) {
echo("出错,请重试或者联系管理员");
die();
}
$result = $sth->execute();
return $result;
}
{
$result = null;
$sql= "SELECT SUM(num) AS num FROM pro1 WHERE proname =?";
$sth = $this->dbh->prepare($sql);
$sth->bindValue(1,$Proname1,PDO::PARAM_STR);
//查询数据库
//执行预处理语句,并将结果保存在$sth中
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);//只返回关联索引
// 显式的关闭PDO连接
$this->dbh = NULL;
// [03]返回结果
return $result;
}function insPP1($ID,$PRO,$PRI,$NUM,$TOT,$DES)
{
$result = false;
$a=$this->getPP($PRO);
$PTO=($a['num']-$NUM);
$sql = "INSERT INTO pro(id,proname,price,num,total,description,inv) VALUES (?,?,?,?,?,?,?)";
try{
$sth = $this->dbh->prepare($sql);
// 准备预处理语句
$sth->bindValue(1, $ID, PDO::PARAM_INT);
$sth->bindValue(2, $PRO, PDO::PARAM_STR);
$sth->bindValue(3, $PRI, PDO::PARAM_STR);
$sth->bindValue(4, $NUM, PDO::PARAM_INT);
$sth->bindValue(5, $TOT, PDO::PARAM_STR);
$sth->bindValue(6, $DES, PDO::PARAM_STR);
$sth->bindValue(7, $PTO, PDO::PARAM_INT);
$result = $sth->execute();
// 执行插入操作并将是否成功的结果保存在一个变量中
$this->dbh = NULL;
$result = true;
} catch (PDOException $err) {
echo("出错,请重试或者联系管理员");
die();
}
$result = $sth->execute();
return $result;
}
try{
$sth = $this->dbh->prepare($sql);
// 准备预处理语句
$sth->bindValue(1, $ID, PDO::PARAM_INT);
$sth->bindValue(2, $PRO, PDO::PARAM_STR);
$sth->bindValue(3, $PRI, PDO::PARAM_STR);
$sth->bindValue(4, $NUM, PDO::PARAM_INT);
$sth->bindValue(5, $TOT, PDO::PARAM_STR);
$sth->bindValue(6, $DES, PDO::PARAM_STR);
$sth->bindValue(7, $PTO, PDO::PARAM_INT);
$result = $sth->execute();
// 执行插入操作并将是否成功的结果保存在一个变量中
$this->dbh = NULL;
$result = true;
} catch (PDOException $err) {
echo("出错,请重试或者联系管理员");
die();
}
$result = $sth->execute(); //这个有点多余
return $result;
}
$a=$this->getPP($PRO);
$PTO=($a['num']-$NUM);$sth->bindValue(7, $PTO, PDO::PARAM_INT);这三句