13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

312 Chapter 13 Advanced <strong>MySQL</strong> Programming<br />

Storage Engines<br />

<strong>MySQL</strong> supports a number of different storage engines, sometimes also called table types.<br />

This means that you have a choice about the underlying implementation of the tables.<br />

Each table in your database can use a different storage engine, <strong>and</strong> you can easily convert<br />

between them.<br />

You can choose a table type when you create a table by using<br />

CREATE TABLE table TYPE=type ....<br />

The commonly available table types are<br />

n MyISAM—This type is the default <strong>and</strong> what we have used so far in the book. It<br />

is based on the traditional ISAM type, which st<strong>and</strong>s for Indexed Sequential Access<br />

Method, a st<strong>and</strong>ard method for storing records <strong>and</strong> files. MyISAM adds a number<br />

of advantages over the ISAM type. Compared to the other storage engines,<br />

MyISAM has the most tools for checking <strong>and</strong> repairing tables. MyISAM tables can<br />

be compressed, <strong>and</strong> they support full text searching.They are not transaction safe<br />

<strong>and</strong> do not support foreign keys.<br />

n MEMORY (previously known as HEAP)—Tables of this type are stored in memory,<br />

<strong>and</strong> their indexes are hashed.This makes MEMORY tables extremely fast, but,<br />

in the event of a crash, your data will be lost.These characteristics make MEMO-<br />

RY tables ideal for storing temporary or derived data.You should specify MAX_ROWS<br />

in the CREATE TABLE statement; otherwise, these tables can hog all your memory.<br />

Also, they cannot have BLOB, TEXT, or AUTO INCREMENT columns.<br />

n MERGE—These tables allow you to treat a collection of MyISAM tables as a single<br />

table for the purpose of querying.This way, you can work around maximum<br />

file size limitations on some operating systems.<br />

n ARCHIVE—These tables store large amounts of data but with a small footprint.<br />

Tables of this type support only INSERT <strong>and</strong> SELECT queries, not DELETE, UPDATE,<br />

or REPLACE. Additionally, indexes are not used.<br />

n CSV—These tables are stored on the server in a single file containing commaseparated<br />

values.The benefit of these types of tables only appears when you need<br />

to view or otherwise work with the data in an external spreadsheet application<br />

such as Microsoft Excel.<br />

n InnoDB—These tables are transaction safe; that is, they provide COMMIT <strong>and</strong> ROLL-<br />

BACK capabilities. InnoDB tables also support foreign keys.While slower than<br />

MyISAM tables, the ability to use transactions in your applications is a worthy<br />

trade-off.<br />

In most web applications, you will generally use either MyISAM or InnoDB tables or a<br />

mix of the two.<br />

You should use MyISAM when you are using a large number of SELECTs or INSERTs<br />

on a table (not both mixed together) because it is the fastest at doing this. For many web

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!