PHP connection to PostgreSQL problem

Source: Internet
Author: User
This time is learning PostgreSQL, I use the PDO mode to operate, connection, increase and remove the check can be normal operation, but found that all the wrong statements will not be error, such as in MySQL an error SQL will directly interrupt and output error messages and error numbers, But PostgreSQL just give the result to a false value, no information and hints, do not know whether it is because of the SQL syntax problem, there is a transaction, there is an error in SQL execution, and finally actually executed successfully ... No catch-out error.
Not clear is where I configure the problem or the operation of the wrong way, I hope to have an understanding of friends can click, thank you!


Reply to discussion (solution)

PostgreSQL does not give error numbers and error messages? This is obviously impossible, but you don't know how to check for errors.
PDO uses two ways to provide error messages:
1. Returns an array using the ErrorInfo method
Array
0 = SQLState error code for ANSI SQL standard
1 = error code defined by the database you are using
2 = error message defined by the database you are using
}
You can determine if there is any error by checking the first
This is the default way for PDO
2. Specify the use exception throw mechanism by setting the value of the property entry Pdo::attr_errmode to Pdo::errmode_exception

try {//Do various database operations here} catch (Pdoexception $e) {die ("error!:". $e->getmessage (). "\ n");}
In fact, the manual is very clear, but you do not read it carefully

PostgreSQL does not give error numbers and error messages? This is obviously impossible, but you don't know how to check for errors.
PDO uses two ways to provide error messages:
1. Returns an array using the ErrorInfo method
Array
0 = SQLState error code for ANSI SQL standard
1 = error code defined by the database you are using
2 = error message defined by the database you are using
}
You can determine if there is any error by checking the first
This is the default way for PDO
2. Specify the use exception throw mechanism by setting the value of the property entry Pdo::attr_errmode to Pdo::errmode_exception

try {//Do various database operations here} catch (Pdoexception $e) {die ("error!:". $e->getmessage (). "\ n");}
In fact, the manual is very clear, but you do not read it carefully


Really should read the manual carefully, thank you very much moderator
  • 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.