What errors actually occur with mySQL / PHP

I am working on a web application using mySQL and have used it in the past. I never saw a mySQL error, and then something during the development process - i.e. poorly formed choose - but as soon as his "work", what mistakes are there?

I have never seen an insertion or choose failure - right? If the syntax is correct, why should they?

I basically ask for this with an eye to figuring out what to do if an error actually occurs. If the insert / update fails, do I sleep the second and try again? How about a choice? How many times before just giving up?

EDIT: Perhaps I asked this badly what I'm looking for: "How should I handle mySQL errors if and when they appear?". In every pattern that I have ever seen, he just died - in a public application that seems very ugly. Should I repeat the command in a few seconds, and then give the user an error and send an e-mail to the administrator? Or just accept that the fatal error will not be fixed.

+6
php mysql
source share
3 answers

Maybe something is just like someone shutting down a MySQL server.
There may be restrictions on the MySQL server. MAX_QUERIES_PER_HOUR .
There may be errors or timeouts when the server disconnects from the client (popular CR_SERVER_LOST ).
The data (file) may be corrupted, which you may notice until the query in the database / table is launched. Your test environment may never have encountered a “too big” situation, but then your production server does.
And much, much more ... Read http://dev.mysql.com/doc/refman/5.1/en/problems.html

+3
source share

Here are some examples of errors that can occur even with syntactically correct SQL statements and which may work in your development environment:

  • Duplicate key violation with INSERT or UPDATE . That is, a PRIMARY KEY or UNIQUE KEY does not allow a column to be set to the same value on another row. Sleep is unlikely to fix this, you need to change the values ​​you insert / update.

  • Constraint violations , such as an unsatisfied link foreign key or setting the NOT NULL column to NULL. You need to insert / update using values ​​that do not violate restrictions. Deleting a string with foreign key dependencies results in an error if you have not defined cascading behavior in the FK constraint declaration. Also, it is an error to insert or update using a value that is outside the scope of the column data type.

  • SQL privileges may limit the operations you can perform.

  • SELECT may throw an error if you dynamically generate queries with application code, and the generated query is erroneous.

  • The requested query may give an error if someone modifies MySQL SQL MODE to be more strict. For example, some implicit data type conversions, or allowing the enforcement of the Single Value rule in GROUP BY queries, may fail.

+3
source share

All this will depend on how you encoded your project. Regardless of whether the selection may fail, it is about how you make the selection in your code. Did you misinform the data? Since this applies to MySQL and PHP, it raises questions about your server, configurations, environment, etc.

There are many ways for potential problems. This question actually cannot be answered without knowing how you will set it all up for a start. Others may include too many open connections, lengthy requests, cache restrictions, blocking, etc. There are too many potential problems to list here exhaustively.

Perhaps you should come back with more specific questions about how to avoid sql injections, misinform data, handle complex queries, etc. The community here will quickly offer quality answers. I'm sure.

0
source share

All Articles