I am learning about PostgreSQL when I connect to PostgreSQL in PHP. I am using the PDO method. connection, addition, deletion, modification, and query can all be performed normally, but no error is reported for all wrong statements, for example, an incorrect SQL statement in mysql will be directly interrupted and an error message and error code will be output. However, postgresql only assigns a false value to the result without any information or prompts, I don't know if it is because of SQL syntax problems. In another case, when an erroneous SQL execution occurs in a transaction, the execution was successful... No catch error.
I don't know where the configuration is wrong or the operation method is incorrect. if you want to know more about it, click it. thank you!
Reply to discussion (solution)
Does PostgreSQL provide error numbers and error messages? This is obviously impossible, but you don't know how to check for errors.
PDO provides error messages in two ways:
1. return an array through the errorInfo method
Array (
0 => ansi SQL standard SQLSTATE error code
1 => error code defined by the database you use
2 => error information defined by the database you use
}
You can check whether the first item is correct or not.
This is the default PDO method.
2. set the property item PDO: ATTR_ERRMODE to PDO: ERRMODE_EXCEPTION to specify the exception throw mechanism.
Try {// perform various database operations here} catch (PDOException $ e) {die ("Error! : ". $ E-> getMessage ()." \ n ");}
In fact, the manual is very clear, but you have not carefully read it.
Does PostgreSQL provide error numbers and error messages? This is obviously impossible, but you don't know how to check for errors.
PDO provides error messages in two ways:
1. return an array through the errorInfo method
Array (
0 => ansi SQL standard SQLSTATE error code
1 => error code defined by the database you use
2 => error information defined by the database you use
}
You can check whether the first item is correct or not.
This is the default PDO method.
2. set the property item PDO: ATTR_ERRMODE to PDO: ERRMODE_EXCEPTION to specify the exception throw mechanism.
Try {// perform various database operations here} catch (PDOException $ e) {die ("Error! : ". $ E-> getMessage ()." \ n ");}
In fact, the manual is very clear, but you have not carefully read it.
I should read the manual carefully. thank you very much to the moderator.