The combination of PHP and MySQL

Document Sample
The combination of PHP and MySQL Powered By Docstoc
					As a concept we already know, the web pages you
create with PHP and MySQL also has architecture
consisting of client and server. Client on the web page of
a web browser. Web browser provides information to
users in the form of HTML Hypertext Markup
Language. While the web application itself is located on
the web server. A relational database server stores the
information required by the application, there are many
options RDBMS Relational Database Management
System, which generally uses Structured Query
Language SQL.

MySQL is one of the open source RDBMS. If you already
know ASP, then PHP has the same function, namely as
a programming language known as middleware. PHP to
process a client request to the request, and interacts with
other programs on the server to satisfy requests from
clients. The combination of PHP and MySQL should be
supported also by the web server. Two options are
popular web server Apache is available in open source
and Microsoft Internet Information Server IIS. Options
web servers tend to follow the operating system
used. Apache is known to run stable on the Unix
operating system Linux, but if you use the Windows
platform, using IIS is more advisable.

Overview of PHP

PHP stands for Hypertext Preprocessor designed for
producing dynamic web pages. Speaking to about PHP,
must include speed as one of its superiority. In terms of
programming, PHP has a resemblance with the language
C. Cross-platform support allows PHP running on
Windows or Unix operating systems, the IIS and
Apache. Set of functions built in to PHP also makes it
easier to build complete web applications. As open
source software, there are thousands of programmers
who participate to develop PHP, which until now has
reached version 5. Fi feature tour that supported, among

1.   Support OOP Object Oriented Programming via
     PHP Data Objects.
2.   Better support in MySQL, is known as extension.
3.   Better support in XML, and so forth.

Overview of MySQL

MySQL development that is pronounced My Ess Queue
Ell and known for its logo dolphins dolphin fish, not
smooth at first. Various criticisms have been obtained
since the initial version, but also time to prove that
MySQL can continue to survive in the ranks based on
open source RDBMS. PHP has prepared a support for
MySQL in particular, makes the combination of PHP and
MySQL is a tool that supports each other to be used by
web programmers.

For small to medium-sized databases, MySQL has a
reliable speed. As well as PHP, MySQL continues to be
developed from time to time by the public open source
community in which copyright is owned by each
individual maker. Until the recent release of MySQL that
has reached version 5, MySQL has had a tour fi cross
platform, Stored Procedures, Triggers, Cursors, Views,
and so forth. Further from the MySQL roadmap is
support for the Partitioning, Online Backup, Event
Scheduling, and others.The combination of PHP and
MySQL has a nickname known as the Dynamic Duo.

Dynamic Duo

In this section, we will discuss the duo PHP and MySQL
in a more practical. Database design is the first thing that
must be drawn in making web applications. In MySQL,
you can perform database administration using the
command line or GUI-based tools such as MySQL
Administrator and MySQL Query Browser. Another
popular option is to use a web application called
phpMyAdmin, which is written using PHP. Activities
create databases, tables, fi eld, execute SQL commands,
to perform the export database you can do in through
phpMyAdmin which has a user friendly web interface. As
with other RDBMS software, the MySQL you can use
SQL commands to create tables and fi eld. To type text
or string data on the fi eld, MySQL provides the following
data types:

1.   Char. Maximum length of characters that can fit the
     data type char is for 255 characters. This data type
     is the type of fi xed length, meaning that if the values
     you enter less than the maximum characters, then
     the remaining characters will be filled with
     spaces.Nevertheless, the remaining spaces will be
     removed at the time of making the fi eld of the table.

2.   Varchar. As in the char, varchar data type also has a
     maximum holding as many as 255 characters. The
     difference is a type varchar variablelength. It means
     character length is adjusted by adding value and not
     be a space such as on the type of fi xed
     length. Although not adding a space, data type
     varchar to add one character that keeps the number
     of characters stored in the fi eld.When do you use
     char or varchar? It depends on your needs, if you
     save the fi eld contains the name, may need to
     provide the fi eld of 30 characters, but do not need
     to save the remaining space for a name that is less
     than 30 characters. For this requirement, you are
     able to define the fi eld with varchar 30. In contrast if
     you want to save a fi eld contains the password, you
     can define it with the char 10 to give a maximum of
     10 characters as a password. Why not use varchar
     10? The consideration, MySQL will check the length
     fi eld every time fi eld with varchar type in the
     update. By using the char 10, MySQL does not need
     to check the number of characters in the fi eld in
     question because the length of the character is fi
     xed length.

3.   TINYTEXT. Is       a  data    type    known      as
     BLOB. TINYTEXT have a maximum of 255
     characters, you can create an index on the entire fi
     eld TINYTEXT.
4.   Text. Can accommodate a maximum of 65.535
     characters.Index can be created on the first 255
5.   Mediumtext. Can accommodate a maximum of
     16,777,215 characters. Index can be created on the
     first 255 characters.
6.   Longtext. Can accommodate a maximum of
     4,294,967,295 characters. Index can be created on
     the first 255 characters.
7.   Enum. With an enum data type, you are able to
     define in advance the value of fi eld. For example for
     the choice of Yes and No. Enum data type can
     accommodate up to 65.535 values.

For numeric data types, MySQL provides an integer data
type int, tinyint, mediumint, bigint, float, double double
precision real, and decimal numeric. Slightly different
between MySQL with other RDBMS is for handling data
type date time. This type of data that you can use is date,
datetime, timestamp, phpMyAdmin as MySQL database
administration support. time, and year. Format used by
MySQL is YYYY MM DD, so if you want to November 30,
2006, the writing is 2006 11 30. With high flexibility,
MySQL can accept writing 06 11 30, 20,061,130, and
061 130 all of which showed 30 November 2006. Both
MySQL and the PHP has many functions to
accommodate the use of this data type date time. In
general, the use of SQL commands in MySQL are not
much different from the SQL command in general, but
MySQL provides some additional SQL commands. One
is the LIMIT command, where you can limit the number
of rows retrieved. For example, the SQL command
SELECT FROM Products LIMIT 0.5 means that you want
to retrieve first 5 rows from the Products table. To take
the next 5 lines, you can use the command SELECT
FROM               Products            LIMIT           5.5.
LIMIT command is commonly used to display the details
of a table on a web page in a paging or a page number
for easy navigation user and does not burden the
network, must be very inconvenient if you have hundreds
of thousands of product details are shown only on one
page, right? It may be that you only get the message
request time out due to a large data collection would
overload your network. After briefly discussing the
MySQL from the back end, it's time to discuss PHP to be
able to create web applications perfectly. To begin to
write PHP code, you need a text editor. You can use a
text editor such as Notepad, but to look and fi tour a
better text editor or if you are too embarrassed to use
Notepad, you can use software text editor such as
EditPlus, UltraEdit, and so forth on the Windows
operating system.

If you use the Unix operating system Linux, a popular
choice is Pico, Emacs, vi, or KEdit. Of course it is
recommended you select a text editor application that
comfortable viewing, as the action just in case if you
have to see the read: write a PHP program code on the
screen for hours and hours non-stop. Before you write
Hello World on the web page and show it off as your
PHP web page first, you need to know that in the fi le
PHP are typed in a text editor, can consist of a
combination of HTML tags, JavaScript, or PHP. In order
for the PHP engine can distinguish the line of code which
is a PHP command, you need to write your PHP code
between the opening tag? Php and closing
tags? . Opening tag?also can be used in addition to
using tags? php. Because the discussion of PHP in this
article is limited to be directed to the combination of PHP
and MySQL which led to the creation of dynamic web
pages that use the database, it will only be given a bit of
introduction on the basic PHP programming. PHP has a
standard programming language commands such as
variable declarations, array processing, looping looping,
logical operators, or the creation function. For those of
you who never learn the language of C or PERL, will see
many similarities and command syntax. On a web page,
information from clients often comes from the HTML
form. For example on a registration page, guest book, or
forums. Such information will be submitted by a user with
the GET or POST method, to then be processed by
PHP. Information entered by the user in the form can be
a textbox, radio buttons, combo boxes, text area, and
others. Form is made up of tagtag HTML that you can
type in a text editor or tools such as Dreamweaver or
The use of the array could be going quite often you come
across in PHP programming. Examples of the use of
multiple arrays is in the combo box, that is the choice that
you can choose more than one item. For example,
favorite color, hobbies, and others. In order for PHP to
know that you want to send a variable array, you must
provide brackets on the variable name. Examples of
HTML tags as follows: SELECT name hobby size 5
above multiple HTML tags to define a multiple combo
box with the name of the hobby, note that the hobby
naming followed by open and close square brackets
indicating an array. PHP itself has a built in variable, that
variable is set by the web server and PHP
environment. To see a list of these variables, you simply
provide a magic command, namely phpinfo.

MySQL API Function
How exactly the Dynamic Duo PHP and MySQL work
together to form a web page that works well? No other
than through the function function is available in PHP
MySQL. This function is called with the MySQL
API. Function function is often used is: 1. MYSQL
CONNECT. Without connecting to the MySQL database,
then there is nothing you can do to process the MySQL
data. The connect function mysql connect to the
database using the username and password that you
specified during the MySQL database administration and
manufacturing. 2. MYSQL PCONNECT.

Functionality is the same function as the function mysql
connect, but there are important differences, namely this
function to let the connection remain in the open despite
the PHP script has finished running. If priority to speed
the web, you can use this function so that PHP does not
need to open a new connection every time a PHP script
that access the MySQL executable. To be able to use
mysql pconnect function, you need to do configuration of
the fi le php.ini in part mysql.allow On mysql.max
persistent persistent persistent mysql.max a line
indicates the maximum number of allowed connections,
the number 1 means no limit. You can replace it with
another number if you want to limit the maximum number
of connections. 3. SELECT MYSQL DB. Function for the
database you want to define the query. 4. MYSQL
QUERY.Function where you can send SQL queries on
tables that you want.Note that this function does not
return the query results for example in the form
recordset, but only open cursor that leads to the results
of the query. You then can take these records with the
query results using one of the function fetch row mysql,
mysql fetch array, or mysql result. 5. MYSQL ROWS
AFFECTED. Mysql function returns the number of
affected rows record the results of the UPDATE,
INSERT, or DELETE. This function is useful to check
whether your query has been running perfectly. Still there
are some commonly used functions such as mysql num
rows, insert id mysql, mysql error, mysql result, and
others that can be used on your web page.


Of course you expect your site visitors come rushing
throng as one sign of the success of your work. But you
also would not expect an error input from the user. Users
are not the ones who should be blamed if an error occurs
on a web application, because here are really valid visitor
is king, even a user who often finds fault intentionally or
unintentionally on a site, can boast of PHP has prepared
a set of function to perform validation.

One of validation that must be done is to avoid quotation
characters input one single quote, quotes two double
quotes, or NULL for MySQL which would confuse these
characters     have     special     meaning       in     SQL
commands. Addslashes function can be used to
overcome these problems. Now maybe you think, means
any information submitted must go through addslashes
function, it could be like this, if you do not have the
authority to change the php.ini configuration fi le that may
have been determined by the provider you use.

But if you have the right to modify php.ini, you can set the
line magic quotes GPC to On, then the function
addslashes no longer needed because it will be done
automatically from the server.However, this configuration
should be worth On by default, you should verify before
deciding not to use the function addslashes.Some other
errors that can arise is if a user enters a string value for
the fi eld that should be entered, the characters inputted
through the length limit fi eld, and so forth.
Although you can use JavaScript for form validation, but
because JavaScript runs on the client side, then you can
not prevent if Javascript is not running on the browser
you used your script or manipulated remember that
mistakes can be committed intentionally by a variety of
purposes. Since it re-input form validation in PHP
recommended if you really really want to keep your web
pages from input errors that could result in the
emergence of security holes that can be penetrated.

PHP for Programmers

Besides ASP PHP, ASP is one of the popular web
programming language and widely used. If you're already
quite familiar with ASP programming language and want
to learn PHP or vice versa, maybe you are just having
trouble finding the equivalent commands ASP version of
PHP. For that may guide the functions below can be

1.    Include. In ASP, you can insert a fi le with the
     command include ASP contoh.asp fi le, while in
     PHP you can use? include contoh.php;? or? require
     an example. php;? .
2.   Page Time Out. Used to set the period of the
     response web page. In ASP you can use the
     command Server.ScriptTimeOut 1000, for PHP to
     use the command set time limit of 1000.

3.   Stop the process. There are times when you want to
     insert a command to stop the script for debugging
     purposes such as programs or other conditions. In
     ASP you use the command Response.end, while in
     PHP you can use the exit, die, or die statement

4.   Move Home Page. One is quite frequently used
     commands are moved antarhalaman web
     programmers. In ASP, you use the command
     Response. Redirect nextpage.asp, while in PHP can
     be used in the command header location:

Which is Better?

Maybe you often heard the debate or the comparison of
the programming language of loyal users who each bring
down each other and not constructive? You can
menganalogikan situation like two people talking, in which
one person speaks the language of ancient Egypt and others to
speak in Singlish Singapore Home, it will not connect,
right? Usefulness of a new programming language is useful if
we as programmers can use it properly and
optimally.Programming languages are tools used to achieve
the goal. Its use is highly dependent on the use and
embodied in the form of real work.