Chapter 4 - Chapter summary

Output
Read the official PHP Manual

Anatomy of a simple database table

  • Name
    • must be unique
    • must contain only alphanumeric characters or underscores. No Spaces!
    • must be less than 64 bytes in length
    • treat names as if they were case sensitive
  • Columns (Attributes)
    • Set column data type
    • Restrict the size or length of data to accept
    • Set any default value if needed (not applicable to the TEXT data type)
    • If field is numeric indicate if you will accept only non-negative values (UNSIGNED).
    • Identify any fields that are required (NOT NULL or NULL).
    • Set table's Primary Key - must be a unique identifier for that row.
  • Rows (Record)

MySQL Data Types

  • Text

    • CHAR[Length] A fixed-length field from 0 to 255 characters long
    • VARCHAR[Length] A variable-length field from 0 to 65,535 characters long
    • TINYTEXT A string with a maximum length of 255 characters
    • TEXT A string with a maximum length of 65,535 characters
    • MEDIUMTEXT A string with a maximum length of 16,777,215 characters
    • LONGTEXT A string with a maximum length of 4,294,967,295 characters
  • Numeric

    • TINYINT[Length] 1 byte Range of –128 to 127 or 0 to 255 unsigned
    • SMALLINT[Length] 2 bytes Range of –32,768 to 32,767 or 0 to 65,535 unsigned
    • MEDIUMINT[Length] 3 bytes Range of –8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned
    • INT[Length] 4 bytes Range of –2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295
    • BIGINT[Length] 8 bytes Range of –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 or 0 to 18,446,744,073,709,551,615 unsigned
    • FLOAT[Length, Decimals] 4 bytes A small number with a floating decimal point
    • DOUBLE[Length, Decimals] 8 bytes A large number with a floating decimal point
    • DECIMAL[Length, Decimals] Length + 1 or 2 bytes A DOUBLE stored as a string, allowing for a fixed decimal point
  • Date and time

    • DATE 3 bytes In the format of YYYY-MM-DD
    • DATETIME 8 bytes In the format of YYYY-MM-DD HH:MM:SS
    • TIMESTAMP 4 bytes In the format of YYYYMMDDHHMMSS - acceptable range starts in 1970 and ends in the year 2038
    • TIME 3 bytes In the format of HH:MM:SS
  • Binary Data

    • BINARY
    • VARBINARY
    • TINYBLOB
    • MEDIUMBLOB
    • LONGBLOB
  • Other

    • ENUM Short for enumeration, which means that each column can have one of several possible values
    • SET Like ENUM except that each column can have more than one of several possible values
    • BOOLEAN A TINYINT(1) field that is either 1(true) or 0(false)

Accessing MySQL

  1. MySQL CLient - runs through the command line interface. To connect to a remote host - must use an ssh tunnel with proper username and password set.
  2. PHPMYADMIN - accessible through your web host login portal. Software that comes with the MySQL Server package. Provides a GUI for database interaction.
  3. MySQL Workbench - nice interface downloadable from mysql.com for interacting with multiple database connections and designing databases from the ground up.
Source
<a target="_blank" href="http://dev.mysql.com/doc/refman/5.5/en/index.html" title="MySQL Manual for version 5.5">Read the official PHP Manual</a>
<h3>Anatomy of a simple database table</h3>
<ul>
	<li>Name
		<ul>
			<li>must be unique</li>
			<li>must contain only alphanumeric characters or underscores. No Spaces!</li>
			<li>must be less than 64 bytes in length</li>
			<li>treat names as if they were case sensitive</li>
		</ul>
	</li>
	<li>Columns (Attributes)
		<ul>
			<li>Set column data type</a></li>
			<li>Restrict the size or length of data to accept</li>
			<li>Set any default value if needed (not applicable to the TEXT data type)</li>
			<li>If field is numeric indicate if you will accept only non-negative values (UNSIGNED).</li>
			<li>Identify any fields that are required (NOT NULL or NULL).</li>
			<li>Set table's Primary Key - must be a unique identifier for that row.</li>
		</ul>
	</li>
	<li>Rows (Record)
		<ul>
			<li></li>
		</ul>
	</li>
</ul>
<h3>MySQL Data Types</h3>
<ul>
	<li><h4>Text</h4>
		<ul>
			<li><b>CHAR[Length]</b> A fixed-length field from 0 to 255 characters long</li>
			<li><b>VARCHAR[Length]</b> A variable-length field from 0 to 65,535 characters long</li>
			<li><b>TINYTEXT</b>  A string with a maximum length of	255 characters</li>
			<li><b>TEXT</b> A string with a maximum length of 65,535 characters</li>
			<li><b>MEDIUMTEXT</b> A string with a maximum length of 16,777,215 characters </li>
			<li><b>LONGTEXT</b> A string with a maximum length of 4,294,967,295 characters</li>
		</ul>
	</li>
	<li><h4>Numeric</h4>
		<ul>
			<li><b>TINYINT[Length]</b> 1 byte Range of –128 to 127 or 0 to 255 unsigned</li>
			<li><b>SMALLINT[Length]</b> 2 bytes Range of –32,768 to 32,767 or 0 to 65,535 unsigned</li>
			<li><b>MEDIUMINT[Length]</b> 3 bytes Range of –8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned</li>
			<li><b>INT[Length]</b> 4 bytes Range of –2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295</li>
			<li><b>BIGINT[Length]</b> 8 bytes Range of –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 or 0 to 18,446,744,073,709,551,615 unsigned</li>
			<li><b>FLOAT[Length, Decimals]</b> 4 bytes A small number with a floating decimal point</li>
			<li><b>DOUBLE[Length, Decimals]</b> 8 bytes A large number with a floating decimal point </li>
			<li><b>DECIMAL[Length, Decimals]</b> Length + 1 or 2 bytes A DOUBLE stored as a string, allowing for a fixed decimal point</li>
		</ul>
	</li>
	<li><h4>Date and time</h4>
		<ul>
			<li><b>DATE</b> 3 bytes In the format of YYYY-MM-DD</li>
			<li><b>DATETIME</b> 8 bytes In the format of YYYY-MM-DD HH:MM:SS</li>
			<li><b>TIMESTAMP</b> 4 bytes In the format of YYYYMMDDHHMMSS - acceptable range starts in 1970 and ends in the year 2038</li>
			<li><b>TIME</b> 3 bytes In the format of HH:MM:SS</li>
		</ul>
	</li>
	<li><h4>Binary Data</h4>
		<ul>
			<li>BINARY</li>
			<li>VARBINARY</li>
			<li>TINYBLOB</li>
			<li>MEDIUMBLOB</li>
			<li>LONGBLOB</li>
		</ul>
	</li>
	<li><h4>Other</h4>
		<ul>
			<li><b>ENUM</b> Short for enumeration, which means that each column can have one of several 
			possible values</li>
			<li><b>SET</b> Like ENUM except that each column can have more than one of several possible values</li>
			<li><b>BOOLEAN</b> A TINYINT(1) field that is either 1(true) or 0(false)</li>
		</ul>
	</li>
</ul>
<h3>Accessing MySQL</h3>
<ol>
	<li>MySQL CLient - runs through the command line interface. To connect to a remote host - must use an ssh tunnel with proper username and password set.
	</li>
	<li>PHPMYADMIN - accessible through your web host login portal. Software that comes with the MySQL Server package. Provides a GUI for database interaction.
	</li>
	<li>MySQL Workbench - nice interface downloadable from mysql.com for interacting with multiple database connections and designing databases from the ground up.
	</li>
</ol>