Prev | Current Page 463 | Next

Emilian Balanescu and Cristian Darie

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

The cart_id field contains a value that uniquely identifies a visitor??™s shopping
cart.
It??™s important to understand that a visitor can have several products in the shopping cart, that each product can
have different attribute configurations, and that a customer can purchase the same product several times, each
with different attributes. For example, a visitor can have a Black/L Torch t-shirt and a Pink/M Torch t-shirt in the
cart. For this reason, the only combination of fields that guarantees the uniqueness of the cart items is (cart_id,
product_id, attributes), which could serve as the table primary key.
But wait! MySQL has a limitation regarding the size of the columns that form a primary key. Trying to create the
primary key as specified earlier triggers the following error: ???#1071 ??“ Specified key was too long; max key length
is 999 bytes.??? What the error basically says is that the cumulated size of the columns forming the primary key
cannot exceed 999 bytes, and in our case the three fields exceed 3,000 bytes (a UT8-encoded character takes
three bytes). This means that if you want to create the primary key of the three fields, you??™d have to limit the size
of attributes to 269 characters. This limitation may or may not be acceptable to you, depending on what you??™re
selling, and even if it is OK today, you might need larger attributes tomorrow!
Our workaround is to create an artificial primary key value??”item_id??”and then use that field as the primary
key.


Pages:
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
Stroiki ślubne teksty piosenek Milky bloczek blog Scott McKenzie