MySQL/PHP Problems

Problem 1 in the article at IBM developerWorks kind of rub me the wrong way.

1. Using MySQL directly

Why not? How is the second code example in that post superior to the first? What I see is that the first example, that uses mysql_* directly, is more readable. The second snippet is a jumbled mess.

The article recommends using PEAR::DB. Is PEAR::DB even PHP5 ready? I don’t know, I don’t use it. The author could have at least used PDO. Still slower, but not as bad and is the future of PHP database abstraction IMO.

He uses a prepared statement to do the select. First, I have tested and I know is slower for MySQL. Second, it is not the end all be all of stopping cross site scripting that a lot of people believe it to be. You can only pass certain value parts of certain clauses. Many applications require more complex dynamic query creation.

As for the rest of the post, I agree with most of it. I would argue that many of the problems are not PHP/MySQL related, but just cases of bad programmers and/or new programmers that don’t know better. They read things written by big companies like IBM and follow one bad example (like using PEAR::DB when its not needed) and start off on the wrong road.

Update:  Seems I am not alone.  Peter, its not bad, you are right.  Kristian backs up my feelings about speed as well.

About these ads

3 Responses to MySQL/PHP Problems

  1. Pierre says:

    If any, it should be MDB2 not DB. But the problem remains the same, when all you need is mysql support, even pdo is a wrong choice (yet).

  2. Arnold Daniels says:

    I agree PEAR::DB can seriously injure the performance of your application. I did a simple benchmark test looping through 2500 rows. PEAR::DB was actually more than 15x as slow as using mysql functions natively.

    Just have a look my comments at: http://www.phpdeveloper.org/news/5169

    Brain has done some benchmarking comparing mysql, mysqli and PDO. The results are published on http://dealnews.com/developers/php-mysql.html

    PEAR::DB as well as PEAR:MDB2 have the advantage above PDO that you can put it in compatibility mode, which minimizes the number of changes you need to do when switching DBMS. This mode makes the package even slower.

    I think that the conclusing should be: If you need application to support multiple DBMS’s use PDO, otherwise use mysqli.

  3. Lukas says:

    PDO is not a database abstraction layer .. its just a unified API. However it does little to help you write portable SQL, which is what MDB2 is all about.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: