PHP PDO, why not throw an exception?

Source: Internet
Author: User
Keywords Php pdo
Tags rtrim

The following code:

/**     * 写入数据     *     * @param  string $table     * @param  array  $data     * @return int     */    public function insert($table ,$data){        try {            $sql = "INSERT INTO ".$this->table($table);            $columns = $values = '';            foreach( $data as $k=>$v ) {                $columns .= "`$k`,";                $values .= ":$k,";            }            $columns = rtrim($columns,',');            $values = rtrim($values,',');            $sql = $sql . " ($columns) VALUES ($values)";            $this->_init($sql ,$data);            unset($sql ,$columns ,$values);            return $this->insertId();        }catch( \PDOException $e ) {            $this->halt($e->getMessage() ,$this->getSql());            return false;        }    }

will generate the following SQL,

INSERT INTO `dba_tables` (`pid`,`sellerId`,`cardNum`,`processUnit`,`proDate`,`dateOfPro`,`shipDate`,`clinicName`,`doctor`,`created`,`doctorEmail`,`doctorMobile`,`treatTime`,`treatDesc`,`patient`,`patientEmail`,`remark`) VALUES (3,0,'2DFBD1-9E27-CFFD-6846-459CA9E9','第二车间',1460476800,1459008000,1463068800,'某医院','某医生',1460507802,'d@a.com','13333333333','','牙','某某某','c@a.com','asfasdf')

Using PHP to execute the above statement, do not present an error or throw an exception.
The PDO throw exception mode has been turned on

 $this->_pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

However, the following error will occur with phpMyAdmin execution

Reply content:

The following code:

/**     * 写入数据     *     * @param  string $table     * @param  array  $data     * @return int     */    public function insert($table ,$data){        try {            $sql = "INSERT INTO ".$this->table($table);            $columns = $values = '';            foreach( $data as $k=>$v ) {                $columns .= "`$k`,";                $values .= ":$k,";            }            $columns = rtrim($columns,',');            $values = rtrim($values,',');            $sql = $sql . " ($columns) VALUES ($values)";            $this->_init($sql ,$data);            unset($sql ,$columns ,$values);            return $this->insertId();        }catch( \PDOException $e ) {            $this->halt($e->getMessage() ,$this->getSql());            return false;        }    }

will generate the following SQL,

INSERT INTO `dba_tables` (`pid`,`sellerId`,`cardNum`,`processUnit`,`proDate`,`dateOfPro`,`shipDate`,`clinicName`,`doctor`,`created`,`doctorEmail`,`doctorMobile`,`treatTime`,`treatDesc`,`patient`,`patientEmail`,`remark`) VALUES (3,0,'2DFBD1-9E27-CFFD-6846-459CA9E9','第二车间',1460476800,1459008000,1463068800,'某医院','某医生',1460507802,'d@a.com','13333333333','','牙','某某某','c@a.com','asfasdf')

Using PHP to execute the above statement, do not present an error or throw an exception.
The PDO throw exception mode has been turned on

 $this->_pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

However, the following error will occur with phpMyAdmin execution

Answer has been deleted, forgive me

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.