MySQL

MySQL

PHP header 500 – manage your mySQL errors

Tuesday, August 21st, 2007 in MySQL, PHP | no comments

From time to time problems appear. mySQL server crashes, some error in a sql query might think it’s time to show her ugly face and in top of all that, the all mighty Google comes to index your page. And when he does, he indexes a page that presents an error or a blank page. How can we stop him from indexing that page? With a header 500 error.

The header 500 error or “Internal Server Error” means that the server has a nasty indigestion and the search engine should come back later to see the page in all it’s splendor. And that’s exactly what it will do. So, how do we trigger that error?

Most scripts use the mysql_query(“some sql”)or die(mysql_error()) sintax. Well, that’s ok because in case of an error, the script stops and the error appears so the debug process can begin. The only problem is that if some error appears, it will be indexed by search engines. (more…)

Tags: , , ,

show rows in category with minimal execution time

Friday, May 18th, 2007 in MySQL | no comments

You’ve all seen or made by now an e-commerce shop. If you look at big shops, they use to show right next to the category name the number of products available in that category – ie: Computers (190). Wel, once again you can do that in more that one way.

First way (and the wrong one if you ask me) is when you select the categories from your database to count the number of products from the database that belong to that category. But the problem with this is that you use much too much resources and when your database grows, you script will slow, sometimes even die. As I said before, this might look easy but is wrong. (more…)

mysql_num_rows vs mysql native count()

Friday, May 18th, 2007 in MySQL | no comments

The big question regarding this issue is: what is fater?

Let’s assume you need to build a pagination script. In order to find the total number of rows that will help you determine the number of total pages, you have to use either mysql_num_rows() or simply make your request using mysql’s count(). (more…)