CREATE DATABASE [IF NOT EXISTS] db_name Creates a database CREATE TABLE [IF NOT EXISTS] tbl_ name col1 col_type, col2 col_ type, .... Creates a table ALTER TABLE tbl_name ADD col col_
Trang 1bool define(string $name, mixed
mixed get_browser([string $user_
Return an object with information about a browser Information will be returned as an array if
$return_array is true Relies on browscap.ini
mixed highlight_file(string
Output the syntax - highlighted source PHP file The source will be returned as a string instead if
$return is true
mixed highlight_string(string
$string[, bool $return])
Output a syntax - highlighted string of PHP code
The string will be returned instead if $return is true
Trang 2Appendix C: PHP6 Functions
752
over the last 1, 5, and 15 minutes
mixed time_nanosleep(int
$seconds, int $nanoseconds) *
Pause execution of the script for a specified number
of seconds and nanoseconds
Trang 3D
MySQL Data Types
This appendix contains a listing of data types that are available in MySQL Visit http://
dev.mysql.com/doc/refman/5.1/en/data - type - overview.html for a complete discussion
on each data type
Numeric Data Types
BIGINT[(m)] [UNSIGNED] Numeric field that stores integers from ⫺ 9,223,372,
036,854,775,808 to 9,223,372,036,854,775,807 m represents the maximum display width Adding the
UNSIGNED parameter allows storage of 0 to 18,446,744,073,709,551,615
bits per value
false, and nonzero values represent true
DECIMAL[(m[,d])] [UNSIGNED] A fixed - point numeric field that can store decimals
m represents the total number of displayed digits d represents how many digits follow the decimal point UNSIGNED allows only positive numbers to be stored
Trang 4Appendix D: MySQL Data Types
754
DOUBLE[(m,d)] [UNSIGNED] A double - precision floating - point number that stores
values from ⫺ 1.7976931348623157E+308 to
⫺ 2.2250738585072014E ⫺ 308, 0, and 2.2250738585072014E ⫺ 308 to 1.7976931348623157E+308
m represents the total number of displayed digits d represents how many digits follow the decimal point
UNSIGNED allows only positive numbers to be stored
FLOAT[(m,d)] [UNSIGNED] A single - precision floating - point number that stores values
from ⫺ 3.402823466E+38 to ⫺ 1.175494351E ⫺ 38, 0, and 1.175494351E ⫺ 38 to 3.402823466E+38 m represents the total number of displayed digits d represents how many digits follow the decimal point UNSIGNED allows only positive numbers to be stored
INT[(m)] [UNSIGNED] Numeric field that stores integers from ⫺ 2,147,483,648 to
2,147,483,647 m represents the maximum display width
Adding the UNSIGNED parameter allows storage of 0 to 4,294,967,295
INTEGER[(m)] [UNSIGNED] Synonym for INT
MEDIUMINT[(m)] [UNSIGNED] Numeric field that stores integers from ⫺ 8,388,608 to
8,388,607 m represents the maximum display width
Adding the UNSIGNED parameter allows storage of 0 to 16,777,215
SMALLINT[(m)] [UNSIGNED] Numeric field that stores integers from ⫺ 32,768 to 32,767 m
represents the maximum display width Adding the
UNSIGNED parameter allows storage of 0 to 65,535
REAL[(m,d)] [UNSIGNED] Synonym for DOUBLE (Note: If REAL_AS_FLOAT mode is
enabled, then REAL is a synonym for FLOAT )
TINYINT[(m)] [UNSIGNED] Numeric field that stores integers from ⫺ 128 to 127 m
represents the maximum display width Adding the
UNSIGNED parameter allows storage of 0 to 255
Trang 5Appendix D: MySQL Data Types
755
Date and T ime Data Types
MySQL Field Type Description
YEAR[(2|4)] Stores a year as either YY or YYYY , depending on whether two or four
digit format is specified (default is four - digit) The range is from 1901 to
2155 in four - digit format, and from 70 to 69, representing years from
1970 to 2069, in two - digit format
String Data Types
the length in bits
[NATIONAL] CHARACTER[(m)] Stores a fixed length character string that is right
padded with spaces m represents the length in characters from 0 to 255
[NATIONAL] CHARACTER VARYING[(m)] Stores a variable - length character string m
represents the length in characters from 0 to 65,535
ENUM( ‘ value1 ’ , ‘ value2 ’ , ) Stores a string value Allows only specified values
to be stored in the field (up to a maximum of 65,535 different values)
in bytes from 0 to 4,294,967,295 (4GB)
Trang 6Appendix D: MySQL Data Types
756
represents the length in characters from 0 to 4,294,967,295 (4GB)
in bytes from 0 to 16,777,215
represents the length in characters from 0 to 16,777,215
SET( ‘ value1 ’ , ‘ value2 ’ , ) Stores a set of string values from the specified list
values (up to a maximum of 64 members)
represents the length in characters from 0 to 65,535
in bytes from 0 to 255
represents the length in characters from 0 to 255
represents the length in bits
Spatial Data Formats
Spatial data is beyond the scope of this book See http://dev.mysql.com/doc/refman/5.1/en/
supported - spatial - data - formats.html for more information on the standard spatial formats used
by MySQL
Trang 7E
My SQL Quick Reference
This appendix lists some quick reference notes for your use These topics are covered in more depth in Chapter 3 and on the MySQL web site at www.mysql.com
Database Manipulation Commands
Use the following commands to create and make changes to your database and tables
CREATE DATABASE [IF NOT EXISTS]
db_name
Creates a database
CREATE TABLE [IF NOT EXISTS] tbl_
name (col1 col_type, col2 col_
type, )
Creates a table
ALTER TABLE tbl_name ADD col col_
type [AFTER col],
Adds a new column to a table in the database
ALTER TABLE tbl_name MODIFY col new_col_type,
Changes columns ’ type definitions
ALTER TABLE tbl_name CHANGE old_
col new_col new_col_type,
Changes columns ’ names and type definitions
ALTER TABLE tbl_name DROP col, Removes columns from a table in the
database
RENAME TABLE old_tbl_name TO new_
tbl_name
Renames a table in the database
Trang 8Appendix E: My SQL Quick Reference
Retrieving Data from the Database
You can access the data stored in your tables with the following statement:
SELECT col1[, col2, ] FROM tbl_name [WHERE condition] [ORDER BY col
You can use * to retrieve all columns in a table:
SELECT * FROM tbl_name
col BETWEEN value1 AND value2
col NOT BETWEEN value1 AND value2
col LIKE value
col NOT LIKE value
col IS NULL
col IS NOT NULL
col IN (value1, value2, value3, )
INSERT [IGNORE] INTO tbl_name [(col1,
col2, … )] VALUES (value1, value2, )
Inserts a row into a table
UPDATE [IGNORE] tbl_name SET
condition [ORDER BY ] [LIMIT count]
Modifies information already stored in the table
DELETE [IGNORE] FROM tbl_name WHERE
Trang 9Appendix E: My SQL Quick Reference
MySQL supports wildcard matching Use to match a single character Use % to match zero or more characters
Selecting from Multiple Tables
You can retrieve information from two or more tables at once by using JOIN s MySQL supports the following syntax variations:
SELECT table1.col1, table1.col2, table2.col1, table2.col2FROM
table1, table2WHERE
or
SELECT table1.col1, table1.col2, table2.col1, table2.col2FROM
table1 JOIN table2 ON table1.col1 = table2.col1
Sorting the Results
You can sort the results of the SELECT query by using the ORDER BY clause (and the optional ascending
or descending qualifier):
Limiting the Results
If you would like to limit the results returned from your query, you can do so with a LIMIT clause:
SELECT * FROM table WHERE col1 = value1 LIMIT [offset,] row_count
Trang 11F
Comparison of Text Editor s
Many software programs are available that you can use to enter all your code They each have different features, some that you might view as better than others, depending on your needs and personal preferences We ’ ve put together the following chart to help you compare apples with apples It lists some of the more popular editors alphabetically and compares them against some common text editor features
Many of these editors provide similar features, so your decision really depends on your budget, your needs, and how comfortable you are with each user interface
You can read more about features not listed here, because many of these editors provide other unique benefits We encourage you to visit the following web sites to download these programs and/or to get more information about them:
Trang 12Appendix F: Comparison of Text Editors
762
Editor
Highlighted Syntax
Spell Checker
Built - in FTP Access
Line Numbers
Word Wrap
PHP Code Auto - Completion
WYSIWYG Web Design Editor
Trang 13Appendix F: Comparison of Text Editors
763
Database Connectivity
Content Preview
Multiple Undo/Redo
Search and Replace
Code Folding
PHP Debugging
CVS/
Subversion Integration Price
Trang 15G
Choosing a Third - Par ty Host
Many people like to run their own servers out of their homes or offices, and that is a feasible solution for hosting, if you have the time and network resources But sometimes hosting your own web site can lead to more problems than it ’ s worth You need to think about backup power, keeping security holes patched, performing regular maintenance and upgrades, and many other issues And keep in mind that not only do you need to have a web server running, but you also need to have something to manage your domain records as well, a Domain Name System (DNS) server
With third - party hosting solutions, you can have trained IT professionals who make sure your web server stays up and running 24 hours a day, at an affordable price It ’ s their job to make sure your site is secure and always available for viewing
Configuration ability: Web server settings/configurations, cron jobs, .htaccess support
Administration GUIs: E - mail, database, user setup Bandwidth usage: Web site, e - mail, streaming media, database connections Price: Based on features, contract time, and other criteria
Trang 16Appendix G: Choosing a Third - Party Host
Keep in mind that you aren ’ t likely to have every combination and possibility with every host, so it ’ s
important that you research your prospective hosts to make a well - thought - out decision before jumping
into a long - term contract To that end, let ’ s get into a little more detail about each of these topics
Supported Languages
Obviously, we ’ re assuming you want to use PHP (you did buy this book, after all), but there are other
languages you may need to use There may be a time when another language, such as Perl, Python, or
even Java, is better suited for your needs than PHP For example, perhaps you have to accomplish
something a client already has set up at a different host or server, using a different programming
language It is nice to at least have the option of using the existing code, rather than spending the time
and money to redevelop the application in PHP
Supported Databases
Again, because this book is geared toward MySQL, we assume you will probably be looking for a host
that supports MySQL However, you can use many other databases with PHP Here are just some of the
databases that PHP can work with:
PHP even comes with the embedded database SQLite enabled Depending on your situation, you may
want to choose a host that has more than one of these databases set up by default Some larger
companies, for example, are using MS SQL as their database, usually because they are using ASP.NET
for programming Should you need to convert any site to PHP, you will be glad to know that PHP can
connect and work nicely with MS SQL as well
Server Control and Access
Many hosts won ’ t give a web developer full access or control over their hosted domain We tend to shy
away from those hosts, because you are more likely to run into problems with them when you want to
do some custom configuration to the server
Look into the type of access your host provides Obviously, your host will give you FTP access so you
can upload your files to the web server Some hosts, however, will give you FTP access but nothing else
The problem is that you are likely to run into a situation in which you want to configure your server For
this, you will need SSH (Secure Shell) access to use the command line
In fact, the ability to configure is often necessary when performing tasks that usually aren ’ t offered by
hosts by default For example, consider htaccess files With htaccess files, you can deny and allow
Trang 17Appendix G: Choosing a Third - Party Host
access to certain files and directories, based on the users you allow using htpasswd (See Chapter 12 for more information on htaccess and htpasswd )
Along with htaccess , most hosts allow you to use cron jobs, but are not likely to set them up for you Therefore, you need to remote into the server and edit the crontab file to enable you to run scheduled tasks There are countless configuration settings that you might want to change, if your host allows you
to configure them Keep all this in mind when choosing your hosting solution
Administration GUI s
Certain hosts offer a dministration graphical user interfaces, (GUIs) or user control panels, as a feature of their packages A lot of people don ’ t really care for GUIs, but when you don ’ t have a choice — either because you don ’ t have sufficient access to the server or you don ’ t fully understand how to get things done at a command prompt — a point - and - click solution can be a wonderful tool
The interface can be as simple as one that allows you to view information about the server, or it can be as complex as one that allows you to install applications and programming languages with the click of a button Also, keep in mind that many control panels have utilities that allow clients to administer their own e - mail users With such a feature, the client can simply log on to the control panel and set up and delete users as the need arises, rather than having to call you or the hosting company to set up an e - mail account
Bandwidth and Site Usage
Bandwidth and site usage both can factor into the overall price of hosting Hosting companies usually give out only so much bandwidth usage per site per month There is usually a hefty charge if you go over that amount Consider the following issues when looking into bandwidth:
Web site traffic
E - mail usage and storage Database connections Streaming media
If you have heavy activity in any or all of these areas, you might get billed for bandwidth overutilization before you know it You need to consider how many people will visit your site on average In addition, some hosts count e - mail usage in the end - of - the - month calculation used to tally your bill Some hosts will even go so far as to monitor your FTP access and count that toward the total bandwidth used
Database connections don ’ t really relate to bandwidth usage, but hosts often limit the number of database connections you can make, as another way to control the number of people allowed to visit the site at one time
Finally, streaming media is very heavy on bandwidth; should you plan to use it as a form of conveying information to the end users of your site, then your hosting bill could rise dramatically
❑
❑
❑
❑