• (cs)

    I don't see the issue. Sure there was a misspelling. And sure the comments might be incorrect.

    But it has logic behind it and no insane syntax tricks. The code is fine.

  • qeury farie (unregistered)

    I wrote this: Query is intentionally spelled not good for the obsfucation purpose and the securities.

  • RuBen (unregistered)

    I thought that the logAllQeurys() function would log all qeuries, but according to the comment, it's logging all the queries..

    I wasn't expecting that!

  • Jimmee (unregistered)

    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions, indeed, done right it's pretty essential in the manner of creating an abstraction layer to allow you to create a lot of convenience and safety - even if you never forsee using anything except mysql.

    Of course, this one isn't done right. But still, he's half way up the first step of the ladder, at least he recognises the need.

  • qeury farie (unregistered)

    I post again to agree. captcha = dolor. My custom CMS will make me a lot of dolor.

  • Obvious Guy (unregistered)

    I'm pretty sure qeury is only consistently misspelt so as to not clash with the name of the function, that is, query.

  • Furiant (unregistered)

    Whatever you're paying this guy, I'll dubble it.

  • Daniel (unregistered) in reply to qeury farie

    I agree, that is if we are using the defintion of dolor (and not a mispelling): http://www.medterms.com/script/main/art.asp?articlekey=24911

  • Francesco (unregistered)

    Geez, what does people expect to find when posting job openings for a PHP project? Programmers?

  • (cs) in reply to Francesco
    Francesco:
    Geez, what does people expect to find when posting job openings for a PHP project? Programmers?
    Right? Isn't this code about par for the coarse ;) for PHP programmers?
  • Manadar (unregistered)

    /* You fail */ SELECT 1 + 1

  • (cs)

    Wow, it's still June? I wish I were a little kid because my summer vacation would have just extended an extra month!

  • q.kontinuum (unregistered) in reply to RHuckster

    [quote user=RHuckster]Wow, it's still June?[/quote]

    Even June, Friday 13th, so it's still 2008, 2003 or even earlier ;-) Don't know how old you will be in the far away Friday 13th of July 2012, but maybe now (2003? 2008?) you are still a lucky child?

  • (cs) in reply to RHuckster

    It's planned for Friday the 13th, something was bound to go wrong... BTW, doews MySQL support the WITH clause? Because that would throw off his 'select' substring a little.

  • Cbuttius (unregistered)

    the way the weather is here in London you wouldn't think it was July or June. More like March or April

  • Cbuttius (unregistered) in reply to q.kontinuum

    [quote user="q.kontinuum"][quote user=RHuckster]Wow, it's still June?[/quote]

    Even June, Friday 13th, so it's still 2008, 2003 or even earlier ;-) Don't know how old you will be in the far away Friday 13th of July 2012, but maybe now (2003? 2008?) you are still a lucky child? [/quote]

    During my lifetime any of 1969, 1975, 1980, 1986. 1997, 2003 or 2008. In future years 2014, 2025, 2031, 2036, 2042 and if I live that long 2053.

  • Sal Paradise (unregistered)

    Lame. Crying over misspelled words and lack of error logging does not make a WTF.

  • Moi (unregistered)

    I bet the code come from France. Not that french are inherently bad programmer, but because the broken english sound very much like french going through google translate.

    Then again, broken english comment may not be the main problem in this code.

  • foo (unregistered) in reply to Moi
    Moi:
    I bet the code come from France. Not that french are inherently bad programmer, but because the broken english sound very much like french going through google translate.

    Then again, broken english comment may not be the main problem in this code.

    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.

  • pantsman (unregistered)

    You deserve this if you use PHP.

  • (cs)

    It makes my eyes bleed...

  • Drtfsxzjkl (unregistered)
    Hey Pittsburgh Readers – who's up for grabbing a couple drinks tomorrow, Friday (June 13) Night at Market Square? Mark, Remy, and I will be there -- just drop me a line and we'll catch up.
    Despite having seen it so many times I still can't wrap my head around the fact that people actually do this (meeting with people you don't know and "grabbing drinks" and chatting) and they enjoy it. I can barely muster enough willforce to greet other people in the morning.
  • Anonymous (unregistered) in reply to Drtfsxzjkl
    Drtfsxzjkl:
    Despite having seen it so many times I still can't wrap my head around the fact that people actually do this (meeting with people you don't know and "grabbing drinks" and chatting) and they enjoy it. I can barely muster enough willforce to greet other people in the morning.

    Maybe that's why it's held at night. :)

  • FragFrog (unregistered) in reply to Jimmee
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions, indeed, done right it's pretty essential in the manner of creating an abstraction layer to allow you to create a lot of convenience and safety - even if you never forsee using anything except mysql.

    Of course, this one isn't done right. But still, he's half way up the first step of the ladder, at least he recognises the need.

    Agreed. The original MySQL wrapper in PHP is clumsy in use to say the least, although the mysqli and PDO classes try to remedy that.

    Almost everything we see in this function (result testing, connection testing, looping over the resultset, getting insert ID's, etc) is common code. Most of this is required for every query you execute. Putting all that in a wrapper so you don't have to copy-paste it time and again is, if anything, good coding practice. And make no mistake: this is a pretty simple way to do so - I have seen versions of mysql wrappers requiring a thousand lines of undocumented code. In comparison, this is neatly done indeed.

    Of course, there are a number of problems with it (lack of flexibility, unpredictable behavior, etc), but the basic idea of a simple method to handle all that tedious default stuff concerning database interaction in PHP, is far from a WTF.

  • (cs) in reply to FragFrog
    FragFrog:
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions, indeed, done right it's pretty essential in the manner of creating an abstraction layer to allow you to create a lot of convenience and safety - even if you never forsee using anything except mysql.

    Of course, this one isn't done right. But still, he's half way up the first step of the ladder, at least he recognises the need.

    Agreed. The original MySQL wrapper in PHP is clumsy in use to say the least, although the mysqli and PDO classes try to remedy that.

    Almost everything we see in this function (result testing, connection testing, looping over the resultset, getting insert ID's, etc) is common code. Most of this is required for every query you execute. Putting all that in a wrapper so you don't have to copy-paste it time and again is, if anything, good coding practice. And make no mistake: this is a pretty simple way to do so - I have seen versions of mysql wrappers requiring a thousand lines of undocumented code. In comparison, this is neatly done indeed.

    Of course, there are a number of problems with it (lack of flexibility, unpredictable behavior, etc), but the basic idea of a simple method to handle all that tedious default stuff concerning database interaction in PHP, is far from a WTF.

    A cow in a dress is still a cow.

  • Dave (unregistered) in reply to RuBen
    RuBen:
    I thought that the logAllQeurys() function would log all qeuries, but according to the comment, it's logging all the queries..

    I wasn't expecting that!

    Incorrect! It log's all hi's query's!

  • Dave (unregistered) in reply to Jimmee
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions

    What is inherently wrong with it, buddy, is that it has already been written for you. You've heard of PDO, surely? And if you don't like that, every single damn framework has its own wrapper already.

    A developer should be given a good slapping for attempting to write their own wrapper.

  • Dave (unregistered) in reply to Sal Paradise
    Sal Paradise:
    Lame. Crying over misspelled words and lack of error logging does not make a WTF.

    Do you really think that's all that's wrong with this code, or are you trolling?

  • Moi (unregistered) in reply to foo
    foo:
    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.

    WHile qeury would be kind of a common mistake in french (the u being totally silent), the specific phrase I was refering to is :

    ///loop through the result and full the array

    It does not make any sense in english. But it is a blind idiot translation of the french phrase. Maybe other language too, but being hideously bad at english is a common quirk of french software engineer, since english comment are mandatory but there is no other reason to learn english.

  • (cs) in reply to PiisAWheeL
    PiisAWheeL:
    A cow in a dress is still a cow.
    But with a wrapper function you don't have to dress the cow yourself.
  • Chuck Lester (unregistered) in reply to Moi
    Moi:
    foo:
    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.

    WHile qeury would be kind of a common mistake in french (the u being totally silent), the specific phrase I was refering to is :

    ///loop through the result and full the array

    It does not make any sense in english. But it is a blind idiot translation of the french phrase. Maybe other language too, but being hideously bad at english is a common quirk of french software engineer, since english comment are mandatory but there is no other reason to learn english.

    Seems to me it could also be spanish ...

  • Ouhlala (unregistered) in reply to Moi
    ///loop through the result and full the array

    It does not make any sense in english. But it is a blind idiot translation of the french phrase. Maybe other language too, but being hideously bad at english is a common quirk of french software engineer, since english comment are mandatory but there is no other reason to learn english.

    Actually, I'm going to go on a limb and say that you are French yourself and you believe that the word the guy wanted to use is "remplir" (fill in English); however, I would think it is more likely to be a typo in this case: see how the U is close to the I on your keyboard and it becomes
    ///loop through the result and fill the array
    which is perfectly goo.. err, OK English... :)

  • (cs) in reply to Drtfsxzjkl

    I definitely have my own personal limits on sociability, but for me it's more of a "hang out with folks once or twice every few months".

    At this point, I'm more worried that I'm going to completely forget and be halfway home before I remember I was planning to meet people after work.

  • Jabba the Hutt (unregistered) in reply to Dave
    Dave:
    You've heard of PDO, surely? And if you don't like that, every single damn framework has its own wrapper already.

    He was creating his own CMS; he obviously can't use someone else's framework because the superiority of his own is his competitive advantage. Mandatory Joel link.

    I wonder if this is a theme among PHP developers. It would not be the first time I've seen one brag about their own awesome CMS. Maybe it is like how template engines proliferate in Python because they are so easy to create.

  • Ozzy (unregistered)

    TRWTF is PHP.

  • Meep (unregistered) in reply to foo
    foo:
    Moi:
    I bet the code come from France. Not that french are inherently bad programmer, but because the broken english sound very much like french going through google translate.

    Then again, broken english comment may not be the main problem in this code.

    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.

    That's true as a rule, but in modern English orthography, 'qu' is very common and associated with the 'kw' consonant sound, so it's not really a vowel confusion, and I'm doubtful that it's accidental.

    Someone suggested he deliberately misspelled it to differentiate it from a library term; that would be TRWTF if that's the case since that's a horrible convention.

  • Meep (unregistered) in reply to Jabba the Hutt
    Jabba the Hutt:
    Dave:
    You've heard of PDO, surely? And if you don't like that, every single damn framework has its own wrapper already.

    He was creating his own CMS; he obviously can't use someone else's framework because the superiority of his own is his competitive advantage. Mandatory Joel link.

    I wonder if this is a theme among PHP developers. It would not be the first time I've seen one brag about their own awesome CMS. Maybe it is like how template engines proliferate in Python because they are so easy to create.

    Joel's got a point... I have no idea about PHP developers, but one thing about web frameworks and web stuff in general is how awful it tends to be. If I were going to hire someone to work on an existing web framework, if he's already written one himself, even if it sucked, at least it means he knows how one works and has already learned some lessons about it.

  • Meep (unregistered) in reply to Ouhlala
    Ouhlala:
    ///loop through the result and full the array

    It does not make any sense in english. But it is a blind idiot translation of the french phrase. Maybe other language too, but being hideously bad at english is a common quirk of french software engineer, since english comment are mandatory but there is no other reason to learn english.

    Actually, I'm going to go on a limb and say that you are French yourself and you believe that the word the guy wanted to use is "remplir" (fill in English); however, I would think it is more likely to be a typo in this case: see how the U is close to the I on your keyboard and it becomes
    ///loop through the result and fill the array
    which is perfectly goo.. err, OK English... :)

    Okay? Aside from dropping punctuation and capitalization, that is perfect American Standard English. All of the comments are fragments without capitalization or punctuation, which is appropriate for comments. As far as fragments can be, they're grammatically perfect. The misspellings all look like typos, except dubble* looks like a learned mistake, he probably inferred it (quite logically) from bubble. Most people have that; I can't, for some reason, get "receive" right without checking it, and always want to pronounce the 'ch' in "chimera" as a "sh".

  • dogmatic (unregistered) in reply to Dave
    Dave:
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions

    What is inherently wrong with it, buddy, is that it has already been written for you. You've heard of PDO, surely? And if you don't like that, every single damn framework has its own wrapper already.

    A developer should be given a good slapping for attempting to write their own wrapper.

    Frameworks create unnecessary overhead, and unless you find in planning that you will need many of a framework's features in any particular project they should be avoided. I've found that often a framework's promise of saving development time is mitigated by the time it takes to get around a framework when it fails to provide needed functionalities. Often framework's are like learning a new language to do something that would be just as easy in straight PHP.

    PDO is great but it also requires access to the server to install the drivers, thus making your code a lot less portable, so not necessarily the best choice for a CMS.

    That being said this guy's approach is not great. Better to make one class that provides all the methods needed to read and write to the database. This class can contain normal mysqli statements and will be the abstraction layer in case you ever need to use something other than mysql. You will have to make sure that all user input gets processed to prevent mysql injection of course.

  • David (unregistered)

    We had someone write a similar (in some ways) wrapper around the standard Python DB query; like this one, it would sometimes return an array of results, and sometimes just a single result (which was itself an array). I'm not sure we ever did convince him that a predictable function return-type is a good idea, but we did make him fix it. :)

  • Jack (unregistered) in reply to Jimmee
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions, indeed, done right it's pretty essential in the manner of creating an abstraction layer to allow you to create a lot of convenience and safety - even if you never forsee using anything except mysql.

    Of course, this one isn't done right. But still, he's half way up the first step of the ladder, at least he recognises the need.

    No, he doesn't recognize the need. He's a cargo cult programmer. All he knows is "good coders create wrapper classes," and he assumes that if he creates a wrapper, his code will be good. He has no idea why creating a wrapper is good (in some cases), so he goes about it all wrong.

  • (cs)

    There are no bad languages. Bad programmers only. and bad programmers can ruin good language like java also, so PHP is not exception to this.

    -A good programmer.

  • foo (unregistered) in reply to Moi
    Moi:
    foo:
    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.

    WHile qeury would be kind of a common mistake in french (the u being totally silent),

    But "eu" is pronounced quite differently from "e" (or "ue") in French.

  • jMerliN (unregistered)

    It seems to be a common theme these days with people just learning PHP. "I'm going to make my own CMS." Some even claim they're going to start a company with it.

    I just point them at the existing mature, debugged projects that have active developers maintaining them and support and say "the only value in writing your own CMS is to learn what not to do, you don't really stand a chance at competing with existing solutions."

    Though I like taking their initiative to create something and using it as a tool to force them to learn how to do things the right way. I ask them what happens if I am evil and I input bad stuff here? You have a box to enter HTML, what if I enter a script tag that steals information from a client's computer or if I embed image tags that don't go to this domain (http://www.somesitewithCSRFvulnerability.com/admin/do/sendUserDatabase/to/[email protected]). What if I use "scary" characters in my query, like quotes? What if I try to write a blog post in Chinese? Why does this script have a state-changing side effect when I issue a GET request on it? You have an XHR here to get the blog content to display, how are you going to make this crawler-friendly so blogs in your CMS are indexable by search engines? What's stopping me from uploading a PHP file when you expect an HTML file? What happens when a bad guy compromises your software and gets access to the database, can he see my password?

    Then I'll introduce them to how we have caching networks built to make the internet faster and ask them why their PHP pages return a 200 with cache control (or worse, a cache control of no-cache, no-store, max-age=0). Then I'll ask them how they can use cache control headers properly to make their site more efficient. I'll ask why are you using jQuery and hosting it locally when Google hosts it on a CDN and everyone who's ever been to YouTube will likely have it cached for 1 year in their browser?

    And on and on. Needless to say, there's a LOT of stuff to consider when making any decent web application especially something as involved as a really good CMS. I would agree that "I'm going to start a company with my own CMS and it's going to be better than Joomla and Drupal" is a big red flag unless this person has serious credentials to back that up.

  • Joe (unregistered) in reply to Jabba the Hutt
    Jabba the Hutt:
    I wonder if this is a theme among PHP developers. It would not be the first time I've seen one brag about their own awesome CMS. Maybe it is like how template engines proliferate in Python because they are so easy to create.

    Yes, writing their own CMS is the "JAPH" of PHP. Everybody has to do it. Except that nobody's a good enough PHP programmer to fit it into a .sig

    --Joe

  • (cs) in reply to Jabba the Hutt
    Jabba the Hutt:
    He was creating his own CMS; he obviously can't use someone else's framework because the superiority of his own is his competitive advantage. Mandatory Joel link.
    Well there is one good advice in there:
    Joel Spolsky:
    If it's a core business function -- do it yourself, no matter what.

    Unfortunately the advice that is missing is:

    not Joel Spolsky:
    If it's not a core business function and there are mature, tested solutions available -- don't do it yourself, or your code will be the real WTF!

    And that is the Worse-Than-Failure that inevitably folllowed.

  • Jazz (unregistered) in reply to FragFrog
    FragFrog:
    Jimmee:
    There is nothing inherently wrong with creating a wrapper around the PHP mysql functions, indeed, done right it's pretty essential in the manner of creating an abstraction layer to allow you to create a lot of convenience and safety - even if you never forsee using anything except mysql.

    Of course, this one isn't done right. But still, he's half way up the first step of the ladder, at least he recognises the need.

    Agreed. The original MySQL wrapper in PHP is clumsy in use to say the least, although the mysqli and PDO classes try to remedy that.

    Almost everything we see in this function (result testing, connection testing, looping over the resultset, getting insert ID's, etc) is common code. Most of this is required for every query you execute. Putting all that in a wrapper so you don't have to copy-paste it time and again is, if anything, good coding practice. And make no mistake: this is a pretty simple way to do so - I have seen versions of mysql wrappers requiring a thousand lines of undocumented code. In comparison, this is neatly done indeed.

    Of course, there are a number of problems with it (lack of flexibility, unpredictable behavior, etc), but the basic idea of a simple method to handle all that tedious default stuff concerning database interaction in PHP, is far from a WTF.

    Using an abstraction layer is good; using a single function for your entire abstraction layer is bad. If the original coder had paid attention to any of the principles of good usage of PHP, I would agree that this is far from a WTF; but the complete lack of object-orientation and typing discipline push it solidly back into WTF territory.

    These days there are a lot of Object-Relational Mapping frameworks available for PHP: Doctrine, RedBean, Propel. Every serious PHP programmer I know either uses an off-the-shelf ORM solution, or makes their own by wrapping some objects around Zend Framework or PDO statements. No serious PHP programmer would use the above function for this.

  • Roujo (unregistered) in reply to qeury farie
    qeury farie:
    I post again to agree. captcha = dolor. My custom CMS will make me a lot of dolor.

    Appropriately enough, "dolor" is Latin for pain. =P

  • (cs) in reply to foo
    foo:
    Actually, this kind of misspelling (confusion of vowels) is more typical of English speakers, esp. American English, where all vowels are pronounced more or less the same.
    WHAT?!

    Did you never read Peter Benchley's article on how to speak French? With its table of French vowels for handy reference:

    "a" -> pronounced -> "ong" "e" -> pronounced -> "ong" "i" -> pronounced -> "ong" "o" -> pronounced -> "ong" "u" -> pronounced -> "ong"

    Add to this the impossible-to-ignore fact that all French consonants are silent, and the profusion of flyspecks that sprout from every letter. (Most French people don't even realize that the Vietnamese, their former colonials, have perpetrated a hilarious satire on the latter, with an average of 3.2 accent marks per letter.)

    Foriegn spelling is wierd.

  • Jockamo (unregistered)

    We get it, you fat nerds don't like php. You've made that quite clear...

Leave a comment on “The MySQL Wrapper Wrapper”

Log In or post as a guest

Replying to comment #:

« Return to Article