I've looked and seen related questions the overall question of handling database constraints inside the application versus native database constraints, but my question is a lot more pointed and particular in relation to how one handles native mysql constraints within application logic designed in PHP.

In other languages/database wrappers, (ADO.Internet for instance) you set your database interaction inside a try/catch also it throws an effective exception, is the situation with php?

Also, does using a strict ORM negate the requirement for database level constraints?

In other languages/database wrappers, (ADO.Internet for instance) you set your database interaction inside a try/catch also it throws an effective exception, is the situation with php?

It will with PDO... and i believe Mysqli however i havent used that inside a couple years and so i might be wrong. Nevertheless it only throws a PDOException... there arent specific exception types for say 'duplicate key' or 'not null'... you need to parse individuals in the message/code from the exception.

Also, does using a strict ORM negate the requirement for database level constraints?

I'd refuse. In most cases its easier to allow the db handle this whether it can because youre likely to convey more overhead should you emulate this with PHP.

The truly amazing myth of try/catch blocks would be that the programmer will produce amazingly robust code and can really have the ability to get over a unsuccessful database query. But a chance to get over a db error is dependent on which type of error there is to begin with -- if there's a sql syntax error, did that code range from user typing inside a query, or from some subroutine that creates the query? Whether it originated from the code, and never the consumer, then calling the code again will just make the same error again, so utilizing a try/catch block is just condemned from the beginning, the query is not likely to run, ever. Which is generally the kind of code you receive from the PHP script running on the web server, you take a question, it fails, you escalate the failure and quit. If, however, you had been writing an interactive application in PHP and also you required to correctly handle db errors, just like a genetic formula which was attempting to evolve valid SQL claims through random mutation (a really strange example, but anyway) you would then acquire some take advantage of try/catch blocks.

This is applicable to database-level constraints too. For those who have some lengthy-running application that must beautifully cope with constraint violations, well you would need to build that robustness yourself. However I imagine very couple of artists are using PHP in by doing this, 99% of php available can be used to dump out web pages, and also the various wrappers and ORMs be affected by it within their designs. There's a better chance that .Internet would be employed to build the kind of free-standing application that needs error recovery logic.

Which in turn leads to an alternative from the original question, when you should use or why ever use database constraints? They're most helpful if you have a very dynamic database structure, in which the relationship between tables isn't known at compile time, i.e. when new tables are produced or modified dropped included in the application itself. You'd want this for any hefty data warehouse, or data mining, or possibly string theory.