Re: "Terms" in PHP
- From: "ZeldorBlat" <zeldorblat@xxxxxxxxx>
- Date: 14 Nov 2005 19:58:36 -0800
>For the script reading:
>
>$query = 'CREATE TABLE blog_entries (
>blog_id INT UNASIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
>title VARCHAR(100) NOT NULL, entry TEXT NOT NULL,
>date_entered DATETIME NOT NULL
>)';
>
>Now, is there an actual definition for the "_id" part of "blog_id" or
>is that just part of the name of the column of this table? (According
>to the book I'm reading it is the first column but was wondering if
>there was more significance behind the "_id" part...(if it means
>something in PHP.)
Just part of the column name...nothing to do with PHP. How you name
the columns in the database is up to you. People tend to name their
primary key columns that way, although there are a lot of alternatives:
*_id
*_Id
*_ID
*ID
*Key
etc...
>Also, it mentions it's an unassigned integer, and that because of this
>it has to be a positive whole number. Why does it have to be a
>positive whole number?
Do you mean *unsigned* integer?
integer = whole number between negative infinity and infinity
unsigned = has no sign, hence is positve
unsigned integer = whole number that is positve (including zero)
Most database systems (well, probably all) offer different datatypes
for storing different types of data. Depending on what you're storing,
they take up different amounts of space. So you typically choose a
type that:
a) stores the type data you want (integer, numeric, string, binary,
etc.)
b) is of an appropriate size
If a particular column only needs to have positive integers, then use
the unsigned integer type (or equivalent). In this way you don't waste
the space that you would otherwise need if you were storing say,
decimal values.
Strings work the same way. varchar(100) and char(100) can contain up
to 100 characters. As far as I know the main difference is that
varchar has a small overhead to store the length of the string that's
currently there, but it only stores the data you put in it. char(100)
will store a single character as a 100 character string. So if the
strings are short or all about the same length, use char, otherwise use
varchar.
I suppose I should reiterate that all of this really has more to do
with the database you're using than PHP.
.
- Follow-Ups:
- Re: "Terms" in PHP
- From: netsurfer802
- Re: "Terms" in PHP
- References:
- "Terms" in PHP
- From: netsurfer802
- "Terms" in PHP
- Prev by Date: Re: global variables
- Next by Date: Php 5 not working on Windows
- Previous by thread: "Terms" in PHP
- Next by thread: Re: "Terms" in PHP
- Index(es):
Relevant Pages
|