PDO插入无法正常工作

时间:2016-06-09 10:52:29

标签: php mysql pdo

我正在尝试使用PDO插入数据,但它不起作用,也没有在错误日志和catch块中显示错误。选择工作,删除工作,但插入不。怎么了?我该怎么办才能修好它?请帮帮我们。

public function storeCoAuthorAffiliations($affiliationData) {
    try {
        unset($affiliationData['affiliationId']);
        //unset($affiliationData['coAuthorId']);
        print_r($affiliationData);
        $this->core->dbh->beginTransaction();
        // insert query
        $stmt = $this->core->dbh->prepare("
                INSERT INTO co_author_profile_affiliations
                       (user_id,co_author_id,department,university,
                        city,country,pincode,website,
                        mobile_personal,phone_office,
                        email_personal,email_office,
                        fax,funding_agency_id)
                 values(:userId,:coAuthorId,:department,:university,
                        :city,:country,:pincode,:website,
                        :mobilePersonal,:phoneOffice,
                        :emailPersonal,:emailOffice,
                        :fax,:fundingAgencyId)");

        $result = $stmt->execute($affiliationData);
        if ($result) {
            $affiliationId = $this->core->dbh->lastInsertId();
            $this->core->dbh->commit();
            return $affiliationId;
        } else {

            // Failed to create user
            $this->core->dbh->rollBack();
            return false;
        }
    } catch (PDOException $e) {
        //$this->core->dbh->rollBack();
        echo $e->getMessage();   
        return false;
    }
}

和$ affiliationData数组是,

Array
(
[:userId] => 35
[:coAuthorId] => 15
[:department] => cse
[:university] => xxx university
[:city] => xxxx
[:country] => xxxx
[:pincode] => xxxx
[:website] => xxxx.com
[:mobilePersonal] => xxxxx
[:phoneOffice] => xxxxxx
[:emailPersonal] => xxxxx@xxx.com
[:emailOffice] => xxxx@xxx.com
[:fax] => 222222222
[:fundingAgencyId] => 5556
)

0 个答案:

没有答案