Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition

Errata and Notes (February 15, 2009)

Thank you for purchasing Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition! We really hope you're enjoying reading this book, and that it is effectively helping you build better web sites with PHP and MySQL Find the most recent version of this document, the latest errata notes and more details about the book at http://www.cristiandarie.ro/php-mysql-ecommerce-2/. Your feedback is welcome at contact@cristiandarie.ro, thank you!

1. Smarty error: ERRNO: 2 TEXT: unlink(C:\tshirtshop.....) [function.unlink]: No such file or directory

This error is generated by Smarty on the Windows platform (confirmed with Smarty 2.6.18 and 2.6.19).

ERRNO: 2 TEXT: unlink(C:\tshirtshop/presentation/templates_c\%%A5 ^A5A^A5A1C73D%%departments_list.tpl.php) [function.unlink]: No such file or directory

The workaround is to edit libs/smarty/internal/core.write_file.php by adding one line of code:

--->   if (file_exists($params['filename']))
        @unlink($params['filename']);
        @rename($_tmp_file, $params['filename']);
    }
    @chmod($params['filename'], $smarty->_file_perms);


    return true;
}

2. PDO error on Windows: ERRNO: 256 TEXT: SQLSTATE[HY000]: General error: 2014 ...

The PDO driver on Windows may throw the following error when you try to execute a stored procedure:

ERRNO: 256 TEXT: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().

The problem is partially documented at http://bugs.php.net/bug.php?id=39858. For development/testing purposes, the workaround is to use an unofficial version of the PDO driver. One version that I have found to work is http://www.emilianbalanescu.ro/tshirtshop/pdo_driver/php_pdo_mysql.dll. You can download this file, copy it in c:\xampp\php\ext\ and restart the Apache server.

Please let me know if you find a more elegant solution, thank you!

3. Link.php, CheckRequest() function (Chapters 6-22)

There's a bug in the CheckRequest method in presentation/link.php that causes an infinite redirect loop in certain conditions.

Bad:

    /* Remove the virtual location from the requested URL
       so we can compare paths */
    $requested_url = self::Build(str_replace(VIRTUAL_LOCATION, '',
                                             $_SERVER['REQUEST_URI']));

Good:

    /* Remove the virtual location from the requested URL
       so we can compare paths */
    $requested_url = self::Build(substr($_SERVER['REQUEST_URI'], 
                                 strlen(VIRTUAL_LOCATION)));

4. shopping_cart_add_product stored procedure (Chapter 12)

The shopping_cart_add_product stored procedure contains a bug which sometimes generates duplicate primary keys in the shopping_cart table (which leads to an error).

Bad:

  -- Create new shopping cart record, or increase quantity of existing record
  IF productQuantity IS NULL THEN
    INSERT INTO shopping_cart(item_id, cart_id, product_id, attributes,
                              quantity, added_on)
           VALUES (UUID(), inCartId, inProductId, inAttributes, 1, NOW());

Good:

  -- Create new shopping cart record, or increase quantity of existing record
  IF productQuantity IS NULL THEN
    INSERT INTO shopping_cart(cart_id, product_id, attributes,
                              quantity, added_on)
           VALUES (inCartId, inProductId, inAttributes, 1, NOW());