Sie sind auf Seite 1von 12

Creating PHP and MySQL Website With WebMatrix

Author : A. SidiQ P. (DnD Sandy Ra) Email : sandy.raharja@gmail.com


Lisensi Dokumen: Copyright 2011 sq.web.id Seluruh dokumen di sq.web.id dapat digunakan, dimodifikasi dan disebarkan secara bebas untuk tujuan pendidikan (bukan komersial (nonprofit)), dengan syarat tidak menghapus atau merubah atribut penulis dan pernyataan copyright yang disertakan dalam setiap dokumen.

1.

Requirements Microsoft WebMatrix o For the installation of Microsoft WebMatrix you can see in the url http://www.sq.web.id/2011/12/how-to-install-microsoft-webmatrix.html. MySQL Database o For the installation of mysql you can see in the url http://www.sq.web.id/2011/11/how-to-install-mysql-database-server-on.html . Creating directory for project PHP Website under "\My Web Sites" directory, for example "C:\Users\sandy ra\Documents\My Web Sites\DnD".

2.

Creating PHP Site 1. Open Microsoft WebMatrix, Go to Start Menu All Programs Microsoft WebMatrix Microsoft WebMatrix. You will see a window that looks like this :

SQ http://sq.web.id 1

2. You will see there are four main options : o My Site o Site From Web Gallery o Site From Template o Site From Folder

3. To get started with our PHP Website , select Site from Folder.

SQ http://sq.web.id 2

4. After finished installation, You should see a window that looks like this :

You will see : a. URL, this is address of your site (example : http://localhost:27598) b. Path, this is path address of directory to save your the site (example : C:\Users\Sandy Ra\Documents\My Web Sites\DnD). SQ http://sq.web.id 3

3.

Open The Workspace and Creating PHP File

1. Click the Files workspace selector to open the Files workspace. 2. In the navigation pane on the left, right click the DnD Directory, and then click New File to creating the PHP file.

3. If you see the Choose a File Type window : o Choose an PHP file, and then in the "Name" textfield type "InfoPHP.php" for rename PHPPage.php o And then click the OK button.

SQ http://sq.web.id 4

4. The next step, if you see the "PHPInfo.php" file in the workspace, now you are ready to write PHP code, type below code into it :
<?php phpinfo() ?>

and then save this file. 5. To launch the InfoPHP.php file in your browser, Click the Run button in the WebMatrix ribbon and select your favorite web browser.

SQ http://sq.web.id 5

6. You should see a window that looks like this :

SQ http://sq.web.id 6

4.

Creating MySQL Database

1. Open your MySQL Command Line Client. To open MySQL Command Line Client Go to Start Menu All Programs MySQL MySql Server 5.5 MySQL 5.5 Command Line Client. 2. If you have seen window MySQL 5.5 Command Line Client, type your password in dialog Enter password and press the button enter on the keyboard. 3. Now you are ready to write SQL code, type below code to creating new database :
MySQL > Create Database `DnDPHP`;

5. Configuring MySQL Database Connections With Microsoft WebMatrix

1. Click the Databases workspace selector to open the Databases workspace. 2. In the navigation pane on the left, right click the Other Connections, and then click New Connections.

SQ http://sq.web.id 7

3. If you have seen window Connect to Database, o In the Name box, type your name database connection (example : DnDPHP). o In the Database Type, choose MySQL 5.x, 6.x. o In the Server box, type localhost. o In the Database box, type your database name (example : DnDPHP). This is the database that will hold your PHP Website contents. o In the Login box, type your username (example : root). This is username to access your database. o In the Password box, type your password. This is password to access your database. o Check in the Add to web.config check box, And then click the OK button.

4. You should see a window that looks like this :

6. Checking your MySQL Database Connections

1. Click the Files workspace selector to open the Files workspace. 2. In the navigation pane on the left, right click the DnD Directory, and then click New File to creating the PHP file. 3. The next step, if you see the "ConnectionMySQL.php" file in the workspace, now you are ready to write PHP code, type below code into it : SQ http://sq.web.id 8

<?php $connect = mysql_connect("localhost","[YourMySQLUsername]", "YourMySQLPassword"); if (!$connect) { echo " Not Connected ...!!!"; } mysql_select_db("DNDPHP") or die ("Database Indak Ado ...!!!"); echo "Connected"; ?>

and then save this file. 4. To launch the ConnectionMySQL.php file in your browser, Click the Run button in the WebMatrix ribbon and select your favorite web browser.

5. If you will see Connected then your MySQL Database Configuration works fine.

7. Creating Table In MySQL Database With Microsoft WebMatrix

1. Click the Databases workspace selector to open the Databases workspace. 2. In the navigation pane on the left, right click the Tables, and then click New Table.

SQ http://sq.web.id 9

3. The next step, if you see the "(YourSite).NewTable" file in the workspace, In the column properties : o In the (Name) box, type your name database connection (example : DnDPHP). o In the Allow Nulls box, choose False to Not Null field or True to Null field . o In the Data Type box, choose data type for field (example : Int). o In the Default Value box, type default value for field (example : 0). o In the Is Identity? box, choose False. o In the Is Primary Key?, choose True for primary column in your table. o In the Length, type length for field (example : 2) .

4. In the navigation pane on the top, click the New column menu to add new column to your table.

SQ http://sq.web.id 10

5. Save your table, press Ctrl+S on your keyboard, if you see the "Save Table" dialog, o In the Table Name box, type your name table (example : Identity). o And then click the OK button.

6. You should see a window that looks like this :

7. To insert data on the Identities table, In the navigation pane on the top, click the Data menu.

SQ http://sq.web.id 11

4. Open your MySQL Command Line Client, type below code to check your table :
MySQL > Use DnDPHP; MySQL > Desc `Identity`; MySQL > Select * From `Identity`;

5. You should see a window that looks like this :

* Good Luck ! * By : DnD ~ Hanya Ingin Berbagi

SQ http://sq.web.id 12

Das könnte Ihnen auch gefallen