PHP Diary | PHP Housekeeping | PHP Scripts | TD Scripts.com
TD Forum - An unthreaded messageboard script to exchange ideas with your site visitors


[back]
WB01624_.gif (281 bytes) 01/14/00 "mySQL field names" WB01626_.gif (272 bytes)[next]

It's all in a (FIELD) name

In mySQL you need to identify the field type for the data it will contain. I encourage you to print out this page and use this as a reference when setting up your mySQL database tables.

CHAR - fixed length strings from 0 to 255 characters 255. If the data in the field name is not long enough, the memory will be created anyway for it, if the data is longer than the length specified the data will be truncated to fit within the space. Led Zeppelin, for example, using CHAR(10) would be Led Zeppel  when saved in the database, whereas AC DC would fit in the space provided, but memory would be allocated for the remaining characters.

   Usage:    artist CHAR(10)

   Tips: CHAR is faster than VARCHAR but uses more space because extra characters to fill the empty space are used. If you know the size of the string will be the same most of the time or all the time, say in a two digit state field like AZ, WA, OR, etc. then use CHAR.

VARCHAR = for flexible string sizes from 0 to 255 characters in length. If you use VARCHAR(10) then the size allocated for AC DC is actually (5) which is different than using CHAR where the size of the field would be (10) no matter what the data inside consisted of.

   Usage:    artist CHAR(10)

   Tips: VARCHAR is slower to process than CHAR but is more efficient for space inside the database because the exact size of the string is contained. If you the size of the string will vary more often than being a consistent size (for example artist names and song names) then use VARCHAR.

INT = for storing integers. Alternately you can set whether the INT is [signed] or [unsigned]. [signed] will be for storing numbers between -2147483648 to 2147483648, and unsigned is for postive numbers only from 0 to 4294967295.

   Usage:    ID INT(10)
            or
         ID INT

   Tips: If you aren't going to be storing any negative numbers, say for a unique ID number that will be incrementing each time a new record is added to the database use INT unsigned, if you need to store negative numbers use INT signed.

DATE = for storing dates. The default format YYYY-MM-DD although mySQL allows for many different ways to store dates.

TEXT or BLOB = for storing strings in sizes from 255 to 65535 characters. TEXT is compared case insensitvely (cAse same as CASE same as Case) whereas BLOB is compared case sensitively.

   Usage:    comments TEXT(300)
         exact_comments BLOB(300)

   Tips: Useful for storing larger amounts of information, say an entire web page.

This concludes my admittedly brief study over what a mySQL database is and what fields can regularly be used. I would recommend buying the O'Reilly book on mSQL and mySQL if you want more information on how to build a mySQL database, database design is kind of out of the scope of my diary entries, but before I started showing you PHP with mySQL, I wanted to give you a brief overview so it wouldn't be total greek. I will be getting into manipulating a mySQL database using PHP in the future and you will see better how you can build some pretty kewl dynamic things for your website.

What other database support is available for PHP?

PHP isn't limited only to mySQL for database support, you can also use ODBC and a driver to get the connection. FilePro, mSQL, Sybase, Velocis, Oracle, are some of the native databases available to use.

We're working on a few new exciting projects so it might be a few days or possibly a week or more before you see any new diary entries (no time for me to study, I'm guessing). Please vote on what you think of this diary entry, your voting will help others determine if this particular diary entry is worth reading :)

How useful was this diary entry? Avg Surfer Rating: 3.81 (199)

[back]WB01624_.gif (281 bytes) 01/14/00 "mySQL field names" WB01626_.gif (272 bytes)[next]

PHP Diary | PHP Housekeeping | PHP Scripts | TD Scripts.com

Copyright 2000 php-scripts.com Last Modified 01/21/00 01:29