Re: cvs: phpdoc /en/reference/mysql/functions mysql-real-escape-string.xml

From: Date: Sat, 16 May 2009 17:10:05 +0000
Subject: Re: cvs: phpdoc /en/reference/mysql/functions mysql-real-escape-string.xml
References: 1 2  Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4023@lists.php.net to get a copy of this message
Hi Hannes, Sorry for not providing more information in the CVS message. There's so many things wrong with it, and even in the absence of those things I would question whether that was the right place for such an in-depth example. It looks like something that usually ends up getting deleted from the user notes. 1. The code isn't wrapped at 80 chars, so the example stretches off the page at several points. 2. The example checks all variables are set before making the SQL connection, which if you think about it, only makes sense in a very tiny set of real world usages. 3. The is_resource check for mysql_connect is just bizarre. It's either a resource, or false. "if ($link)" is faster, simpler and more readable. Worse still is that the example wraps the rest of the action in a conditional (rather than just dying), and doesn't actually notify the user a problem occurred. 4. The magic quotes check highlights an interesting problem but doesn't discuss it. A cleaner and more reusable approach would be pre-processing the whole POST array. That way huge amounts of code won't need to be modified in PHP6 (when get_magic_quotes_gpc is gone). Although it's not as much of a problem now, the whole issue should probably be discussed on that page. 5. The check to see if the query executed is so strange. Either there was an error (mysql_query returns false) or the row was inserted. I don't understand why anyone would use "if (mysql_affected_rows($link) > 0) {", it's trying too hard to be fancy at the cost of readability and sensibility. Do you disagree, or are you highlighting the need for more informative CVS messages? :) Best wishes, Aidan On Sat, May 16, 2009 at 4:46 PM, Hannes Magnusson <hannes.magnusson@gmail.com> wrote: > On Sat, May 16, 2009 at 15:43, Aidan Lister <aidan@php.net> wrote: >> aidan           Sat May 16 13:43:53 2009 UTC >> >>  Modified files: >>    /phpdoc/en/reference/mysql/functions        mysql-real-escape-string.xml >>  Log: >>  Remove terrible "best practice" example >> > > What was wrong with it? > > -Hannes >

« previous php.doc.cvs (#4023) next »