Month: November 2005

  • Truncation

    Assume the following has completed correctly:

    CREATE TABLE test (
    charField varchar(5)
    );

    What is the end difference between the following two statements?

    INSERT INTO test (charField) VALUES ("123456");
    INSERT INTO test (charField) VALUES ("12345 ");

    Answer: In both cases, the inserted value is trimmed to ‘12345’. For the first, a warning is issued. For the second, only whitespace is trimmed, so no warning.

  • Concatenate

    What, if anything, is the minimum change (fewest inserted/deleted/modified characters) required to make the output The result is bar:


    <?php
    class A {
      private $foo = "bar";
      public function __toString() {
        return $this->foo;
      }
    }

    $myObject = new A();
    echo "The result is " . $myObject;
    ?>

    Answer:
    echo "The result is " , $myObject;

  • User Experience

    I had a positive user experience at the MySQL website the other day while registering for a webinar. The site knew I was logged in, and filled out as much of the form for me as it could. When I added the missing pieces of information, that next page noticed and provided a single-click where I could add the data to my profile. Added functionality, but completely unobtrusive – that’s the user experience I like.

  • What are ‘gotchas’?

    At work, we play a little game called “Tech Team Quiz”.

    Whenever we stumble across a bit of code that behaves oddly, or gives unexpected results that turn out to be documented clearly in the manual, or just contain some devious little error that took a long time to hunt down, we post it as a challenge for the others. For the purpose of this blog, I’ve dubbed them “gotchas”.

    Read carefully – sometimes it’s bad syntax, sometimes it’s behavior that changed between recent versions (for PHP, you can assume version 5.0; for MySQL, it could be anything from 4.0 to 5.1).