Defining PHP sites with Dreamweaver CS6

Source: Internet
Author: User
Tags echo date php development environment php mysql blank page
Because the PHP file needs to be handled by the WEB server, you need to inform Dreamweaver of the location of the test server. You also need to tell Dreamweaver the correct URL to use when testing the file. The following instructions assume that you have set up a local test environment on your computer as described in the section above.

In theory, you can find PHP files anywhere on your computer, and Dreamweaver copies them to the test server when you use Live View or preview in browser. However, this generates two identical copies for each file. The project files are typically stored in a folder in the document root of the test server, which you will also do in this tutorial.

By the way, developing PHP sites requires installing xamp,iis,wampserver including Apache server, MySQL, and phpMyAdmin installation, installation specific process (omitted here)

Finally, install the file in a file directory, C drive, or D drive.

The URL for the document root is http://localhost/.

In Dreamweaver, choose Site > New site. In the Site Name text box, type the name of the site, such as PHP Test site. This name is used to identify this item in Dreamweaver. Click the folder icon next to the Local site folder text box to browse to the document root of the test server. Create a subfolder of the document root named Php_test and select it. Click Open, and then select (On your Mac, select). Verify the settings in the Site Settings dialog box (see Figure 12), and then click Save. (The location of the local site folder depends on how PHP is installed.) )

Note: The folder name should not contain any spaces or special characters. The folder or file name of a Web site cannot use spaces or special characters because they cause problems on most PHP servers.

This is everything you need to define your site in Dreamweaver. You do not need to define a remote or test server unless you want to use them. However, do not close the Site Settings dialog box because you are testing the site right away.

Specifying a test server for Dreamweaver

To specify a test server:

Select Server from the column on the left side of the Site Settings dialog box. Click the plus (+) button in the lower left corner of the dialog box to add a new server. In the dialog box that opens, make sure that the basic button is selected, and then select Local/network from the Connect using list. Name the server, such as Local testing. Set the server folder to the folder specified as the local site folder; In this case, php_test (in the document root of the server). For Web URL, type the URL that you want to use to reach the Php_test folder (in the document root of the server). Because the document root is equivalent to http://localhost/, you need to type the Advanced button at the top of the http://localhost/php_test/selection dialog box in the Web URL text field. It displays the remote server and test server options. For server model (in the Test server section), select the PHP MySQL diagram: click Save. This is a test server, so be sure to select the Test check box in the Site Settings dialog box. Uncheck the "remote" checkbox, as required, below:

Click Save to save the changes you made.

Test PHP Site

You have defined the site in Dreamweaver and can now test whether everything is working.

Choose File > New, create a blank page and select PHP as the page type. Open the Code view,Type the following code between the tags:

The time is now .

The code between the tabs displays the current time.

Switch to Design view and save the page as timetest.php. Html

The text between the tabs is displayed normally, but the PHP code is replaced with a golden shield

No way?

If the time in Live view is not displayed correctly, check the following:

is the WEB server (Apache or IIS) running? Unless you configure the server to run automatically, you will need to start it manually before you can process the PHP page. Does the Web URL point to the same location as the server folder (see Figure 13)? The server's document root (Htdocs, wwwroot, or WWW, depending on your PHP settings) is equivalent to http://localhost/. If your site is in a subfolder of the document root, you need to add the name of the subfolder to the URL. If you are using the MAMP default port, have you added: 8888 after localhost? Does the security software block access to ports 80 and 3306 (or ports 8888 and 8889 If you use the MAMP default value)?

Working with sample files

The PHP site is now defined and functioning properly. The next step is to add the sample files to the test site to prepare for connecting to the database.

If you have not already done so, download the sample files for this tutorial, unzip them and copy them to the Php_test folder (in the server's document root). You can see the sample files in the files panel (see Figure 18). You may need to click the Refresh icon at the top of the files panel to see these files.


Creating MySQL databases and user accounts

MySQL is not a database, but a database management system. You create a database in MySQL. Superuser Root has Full control over all databases, so you need to set up a restricted user account to prevent unauthorized users from accessing other people's data.

In this section, you will use the PhpMyAdmin front end of MySQL to create a database, import sample data, and create a MySQL user account. These instructions assume that you have installed XAMPP on Windows, installed MAMP on your Mac, or have created your own PHP test environment using a WEB server, PHP, MySQL, and PhpMyAdmin.

Create a new database and import the data

To perform this task:

Verify that the WEB server and the MySQL server are running. Start PhpMyAdmin. In most cases, you can complete the operation by typing http://localhost/phpmyadmin/in the browser address bar.

If you use MAMP in Mac OS X, you can use http://localhost/MAMP/or http:localhost:8888/mamp/, and then click the PhpMyAdmin link.

If you installed XAMPP in Windows, type root as your user name, and then type your MySQL root password when prompted.

You should see the phpMyAdmin Welcome screen

Picture below:
Type php_test in the text box labeled Create New Database, and then click Create.

Note: When selecting database and database column (field) names, do not use spaces or hyphens; only numeric characters and underscore characters (for example, Feedback_demo) can be used. Although phpMyAdmin accepts spaces and hyphens, they require special processing and may cause problems. It's a good idea to use all lowercase, because Windows MySQL automatically converts the names to lowercase and handles them in a case-insensitive manner. Most PHP sites are hosted by Linux servers, which are case-sensitive. If the name contains uppercase characters, everything will be corrupted when uploading the Web application from Windows to a Linux server.

Note: You can ignore the "Collation" setting unless you are using a language other than English. "Collation" determines the sort order of the records. If you use English, you can use the default settings.

When PhpMyAdmin reports that the Php_test database has been created, click the Import tab at the top of the page. In the File to Import section, click Browse beside the location of the text File textbox and select Php_test.sql (it is in the assets folder of the PHP test site). Click "Go" at the bottom of the page. At this point, the sample data is imported into the database. Do not close phpMyAdmin because it will continue to be used in the next section.

Create a MySQL user account

The root superuser is only used when performing administrative tasks in PhpMyAdmin because it erases all data. Once deleted, the data will not be restored! There are no tools like Windows Recycle Bin or Mac trash in MySQL. Therefore, the next task is to create a MySQL user account with restricted permissions. Follow these steps to create an account that can access only the Php_test database:

Click the icon in the upper left corner of the phpMyAdmin screen like a small house to return to the original Welcome screen (see Figure 19). Click on the "Privileges" tab at the top of the Welcome page.

Note: Many of the features in PhpMyAdmin are context-sensitive. There is a "privileges" tab at the top of each screen, but to create a new user account, you must return to the Welcome page and click the "Privileges" tab there.

Click Add A New User (near the bottom half of the page). In the User Name text box, type Phptestuser. Select "Local" as "Host". This will enter localhost in the next text box, specifying that the user can only access the local test environment. Type a password in the Password field and type the password again in the next field. The rest of the page remains the same, and then click Go at the bottom of the page.

The next screen confirms that a new user has been added. The "Global Privileges" section provides the user account with the same permissions for all databases. For this tutorial, you will specify that the user can only access the Php_test database.

Scroll down to the "Database-specific Privileges" section and select "Php_test" under the database diagram:

Note: There is a backslash before the underscore in the database name. In some environments, this underscore can be used as a wildcard in MySQL, where the backslash is to ensure that the underscore is used as a text character. However, this is an exceptional case. In general, you should not place backslashes before the underscore in a database, table, or column name.

On the next page, you can set user permissions for the selected database. For a WEB application, you typically only need four permissions: SELECT, INSERT, UPDATE, and DELETE. Select them and click on the "Go" chart:

Set the SELECT, INSERT, UPDATE, and DELETE user rights for the WEB application.

You have now created a MySQL user account that can access the Php_test database. In the next section, you will learn how to create a MySQL connection in Dreamweaver.

Connecting to a database

The sample file contains comments.php, which is used to query the Php_test database and display the results. The dynamic text object in the "Customer Comments" section of the central section of the page (see Figure 22) shows where the results are displayed. Before you can view the results, you need to create a database connection.

Open comments.php. You must open a PHP page in the Document window to create a MySQL connection. In the Databases panel (choose Window > Databases), click the Plus (+) button on the panel and select "MySQL Connection".

The MySQL Connection dialog box is displayed.

Type Conntest as the connection name. For MySQL Server, type localhost.

If you use the MAMP default port on your MAC, use localhost:8889.

For "User Name", type Phptestuser. In the Password field, type the password that you selected for the Phptestuser account. For "Database", type Php_test.

Note: There is no need to place a backslash before the underscore. In the previous section, PhpMyAdmin inserts a backslash (see Figure 20) because PhpMyAdmin uses a query that allows wildcard characters.

Click "Test".

Dreamweaver will attempt to connect to the database. If the connection fails, do the following:

Check the server name, user name, and password. Check the settings for the folder that Dreamweaver uses to process dynamic pages (see Specifying a test server for Dreamweaver). Verify that both the WEB and MySQL servers are running. Temporarily disable any firewalls or security programs. If the connection is valid, you need to configure the security program to allow Dreamweaver to communicate with MySQL. Click "OK". The new connection will appear in the Database panel. Expand the Conntest connection, and then expand the Tables branch. You will see the comments table in the database, and expand it to display the details of the table columns. Click the Live View button. Dynamic text objects in comments.php are replaced with data retrieved from the database (see Figure 24).

Your PHP development environment and site are now set up to start developing PHP Web applications in Dreamweaver.

Follow-up work

This tutorial shows you how to set up a PHP development environment, define a PHP site, and connect to a MySQL database. Defining a site and testing server, and establishing a MySQL connection are the foundation for developing PHP WEB applications in Dreamweaver. You are now ready to use PHP to develop dynamic Web sites in Dreamweaver.

There are many PHP development environments, here are the Dreamweaver cs6,
It writes PHP registration form validation better, the code is easy to debug end,
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.