thinkphp getting MySQL errors

Source: Internet
Author: User

When I recently used thinkphp to find an error message that could not capture MySQL, such as inserting a primary key duplicate data into a table, the program is stuck on that statement as follows

:(

SQLSTATE[23000]: Integrity constraint violation:1062 Duplicate entry ' 1 ' for key ' PRIMARY 'Wrong location

file:d:\*****\thinkphp\library\think\db\driver.class.php line:226

TRACE

#0 d:\*****\thinkphp\library\think\db\driver.class.php (226): Pdostatement->execute ()


Invalid using try catch in code, last modified Driver.class.php file

In 169 rows and 226 rows.

$result = $this->pdostatement->execute ();

Revision changed to

Try{Lighthouse
   $result=   $this -pdostatement->execute ();
}Catch(\pdoexception$e) {
   Echo' querystr= '.$this -Querystr.' <br/> ';
   Print"Error:". $e->getmessage ()."<br/>";
   return-1;
}

This gives you the flexibility to handle PDO errors, and of course the code that displays the error message can be changed to send an email to the administrator, or to log functions.

This method changes the bottom of the frame, and later upgrades will be more troublesome. Any friend who has a better way is also kindly advised.

thinkphp getting MySQL errors

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.