Execute()方法返回对象(PDO)而不是进行查询

时间:2012-12-03 01:15:21

标签: php class object pdo

public function saveWorker($group) {
    if(!(isset($this->conn))) parent::__construct();
        try
        {
            $this->conn ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //catch exceptions
            $q = 'INSERT INTO :group(name, surname, dob, skills, postcode, street, email, tel, erefnumber) VALUES(
            :name,
            :surname,
            :dob,
            :skills,
            :postcode,
            :street,
            :email,
            :tel,
            :erefnumber)'; //sql query with group name
            $stmt = $this->conn->prepare($q);
            $stmt -> bindValue(':group', $this->group, PDO::PARAM_STR);
            $stmt -> bindValue(':name', $this->name, PDO::PARAM_STR);
            $stmt -> bindValue(':surname', $this->surname, PDO::PARAM_STR);
            $stmt -> bindValue(':dob', $this->dob, PDO::PARAM_STR);
            $stmt -> bindValue(':skills', $this->skills, PDO::PARAM_STR);
            $stmt -> bindValue(':postcode', $this->postcode, PDO::PARAM_STR);
            $stmt -> bindValue(':street', $this->street, PDO::PARAM_STR);
            $stmt -> bindValue(':email', $this->email, PDO::PARAM_STR);
            $stmt -> bindValue(':tel', $this->tel, PDO::PARAM_STR);
            $stmt -> bindValue(':erefnumber', $this->erefnumber, PDO::PARAM_STR);

            $results = $stmt->execute();
            if($results > 0)
            {
                      return 'Dodano: '.$ilosc.' rekordow';
            }
            else
            {
                      return 'Wystapil blad podczas dodawania rekordow!';
            }
        }
        catch(PDOException $e) 
        {
          return 'There was some error: ' . $e->getMessage();
        }
        unset($stmt);
}

我有将数据保存到数据库的功能。执行代码: $worker->saveWorker('workers');给了我对象(PDO)#5(0){}

看起来它显示了对象的var_dump,但我在代码中没有这样的东西。

0 个答案:

没有答案