preview

PHP with MySQL

Better Essays

Using PHP5 with MySQL
So now that you’ve done some really cool stuff with PHP in Chapter 2, such as using includes and functions, it’s time to make your site truly dynamic and show users some real data. You may or may not have had experience with databases, so we’ll take a look at what MySQL is and how PHP can tap into the data. We will also show you what a MySQL database looks like in terms of the different tables and fields and give you some quickie shortcuts to make your life much easier (you can thank us later for those).
By the end of this chapter, you will be able to:
❑ Understand a MySQL database
❑ View data contained in the MySQL database
❑ Connect to the database from your Web site
❑ Pull specific information out of the …show more content…

As you answer each of these questions, keep in mind the potential values that could exist for the particular field you’re setting up.
First, ask yourself, will the field contain both letters and numbers?
❑ If the answer is “yes,” consider char, varchar, text, tinytext, mediumtext, longtext, blob, tinyblob, mediumblob, longblob. Then ask yourself how many characters will need to be stored? Will it vary from entry to entry?
❑ How many characters will need to be stored? Will it vary from entry to entry?
❑ 0–255 characters, variable length: Use varchar if you want to delete any trailing spaces, or if you want to set a default value. Use tinytext if you don’t care about trailing spaces or a default value or if your text does not need to be case-sensitive. Use tinyblob if you don’t care about trailing spaces or a default value, but your text does

need to be case-sensitive.

88

Chapter 3
❑ 256–65536 characters: Use text if your text does not need to be case-sensitive in searches, sorts, or comparisons. Use blob if your text is case-sensitive.
❑ 65537–1677215 characters: Use mediumtext if your text does not need to be case-sensitive; use mediumblob if your text is case-sensitive.
❑ 1677216–4294967295 characters: Use longtext if your text does not need to be casesensitive, use longblob if your text is case-sensitive.
❑ If the answer is “Yes, it may contain letters or numbers, but it must be one of a finite number of values,” use enum.
❑ If the

Get Access