PHP Pass Query语句作为参数

时间:2015-03-26 00:51:43

标签: php pdo

我是OOP的新手,我有至少5个具有相同查询的按钮(完成,取消,添加备注等....)唯一的区别是Query语句。 我试图把它放在一个类中并调用 SQL STATEMENT 作为我的参数。但它不起作用。你能告诉我什么是错的或有没有解决方法?谢谢!

      if(isset($_POST['cancel_job'])){
           $strcancel_remarks= trim($_POST['strcancel_remarks']);

           $sql =
                "UPDATE jrf_tbl SET 
                strremarks =  '$strcancel_remarks', //this is the only difference
                strstatus = 'Cancelled'     //this one also      
                WHERE ID =?";

           $set_id = 1;

           $obj = new myclass();
           $obj->updatequery($sql,$set_id)
          }

=====================
    class.php

        <?php

        include_once('dbc.php');

        class myclass{

        private $db;

        public function __construct(){

            $this->db = new Connection();
            $this->db = $this->db->dbConnect();
        }

        public function updatequery($sql, $set_id){
              $stmt = $this->db->prepare($sql);
                $stmt->bindparam (1,$set_id);
                $stmt->execute();

                if($stmt->rowcount()==1){
                    echo "Updated Succesfully.";
                }else{
                    echo "There is an error";
                };
          }
        }

0 个答案:

没有答案