Web Design

(Nancy Kaufman) #1

302


Connect PHP to the Database .................................


3 Type mysql_connect
(‘localhost’,
‘root’);.
Note: A default installation of
MAMP and WAMP does not set up
passwords, so you do not need to
provide one in this example.


1 In your editor, open a new,
blank document.

2 Type <?php.


Connect PHP to the Database


I


n order for your PHP pages to display database information, you need to connect PHP to the
MySQL server. To do this, you can call the PHP mysql_connect function, which takes three
arguments: the address to the server, the username, and the password. Once you have connected,
you can call the mysql_select_db function, which takes a single argument: the name of the
database on the server you will be using. Although these can be placed in each file, it is much easier
to put these functions in their own file, which can be included into other PHP documents as needed.

1


2


3

Free download pdf