Use Dreamweavercs6 to define a PHP Site. because PHP files need to be processed by the Web server, you need to inform Dreamweaver of the location of the test server. You also need to tell the Dreamweaver test file to use the correct URL. Assume that you have set up a local test environment on your computer as described in the preceding section.
Theoretically, you can find PHP files anywhere on your computer. when you use "real-time view" or "preview in a browser", Dreamweaver copies them to the test server. However, this will generate two identical copies for each file. Generally, project files are stored in the document root folder of the test server. you will also do this in this tutorial.
By the way, to develop a PHP Site, install xamp, iis, wampserver, including the Apache Server, MySQL, and PHPmyadmin. the installation process is omitted here)
Finally, install the file in a file directory, drive C, or drive D.
The URL of the document root is http: // localhost /.
In Dreamweaver, select "site"> "new site ". In the Site name text box, type the Site name, 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 view the document root of the test server. Create a sub-folder named php_test and select it. Click open and select (select on Mac "). Verify the settings in the site settings dialog box (see Figure 12) and click save ". (The location of the "local site folder" depends on the PHP installation method .)
Note: the folder name should not contain any space or special characters. The folder or file name of the website cannot contain spaces or special characters, because they may cause problems on most PHP servers.
This is everything you need to define your site in Dreamweaver. No need to define remote or test servers unless you want to use them. However, because you want to test the site immediately, do not close the "site settings" dialog box.
Specify the test server for Dreamweaver
To specify the test server:
Select "server" from the column on the left of the "site settings" dialog box ". Click the plus sign (+) in the lower-left corner of the dialog box to add a new server. In the displayed dialog box, make sure to select the "basic" button and select "local/network" from the "connection usage" list ". Name the server, such as Local Testing. Set "server folder" to the folder specified as "local site folder". In this example, php_test (in the document root of the server ). For "Web URL", type the URL to be used 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 http: // localhost/php_test/in the "Web URL" text field and select the "advanced" button at the top of the dialog box. It displays options for remote servers and test servers. For "Server model" (in the "test server" section), select "PHP MySQL" and click "save ". This is a test server, so be sure to select the "test" check box in the "site settings" dialog box. Deselect the "remote" check box as needed, as shown in the following figure:
Click Save to save the changes.
Test the PHP Site
You have defined a website in Dreamweaver and can now test whether everything works.
Select "file"> "new", create a blank page, and select "PHP" as the page type. Open the "code" view and goEnter the following code between tags:
The time is now .
The code between tags displays the current time.
Switch to the design view and save the page as timetest. php. HTML
The text between labels can be normally displayed, but the PHP code is replaced with a golden shield
No?
If the time displayed in "real-time view" is incorrect, check the following items:
Is the Web server (Apache or IIS) running? Unless you configure the server to run automatically, you must manually start it before processing 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 sub-folder at the root of the document, you need to add the sub-folder name to the URL. If the MAMP default port is used, is: 8888 added after localhost? Does the security software block access to ports 80 and 3306 (or ports 8888 and 8889, if the MAMP default value is used )? Example file
The PHP site is defined and running properly. The next step is to add the sample file to the test site to prepare for connecting to the database.
If you have not yet done so, download the sample files for this tutorial, decompress them, and copy them to the php_test folder (in the document root of the server ). In this case, you can see the sample file in the file panel (see Figure 18 ). You may need to click the "refresh" icon at the top of the "files" panel to view these files.
Create a MySQL database and user account
MySQL is not a database, but a database management system. Create a database in MySQL. Super User root has full control over all databases. Therefore, users with limited permissions need to be set up to prevent unauthorized users from accessing others' 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, MAMP on Mac, or you have used Web servers, PHP, MySQL, and phpMyAdmin to create your own PHP testing environment.
Create a new database and import data
To execute this task:
Verify that the Web server and MySQL server are running. Start phpMyAdmin. In most cases, you can type http: // localhost/phpmyadmin/in the address bar of your browser to complete this operation.
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 XAMPP is installed in Windows, enter root as the user name and enter your MySQL root password when prompted.
You should see the phpMyAdmin welcome screen
Figure:
In the text box labeled "Create New Database", type php_test and click "Create ".
Note: Do not use spaces or hyphens when selecting the names of database and database columns (fields). you can only use numeric and underline characters (for example, feedback_demo ). Although phpMyAdmin accepts spaces and hyphens, they must be specially processed and may cause problems. It is also a good way to use lower case letters, because Windows MySQL will automatically convert names to lower case letters and process them in case-insensitive form. Most PHP sites are hosted on Linux servers, which are case sensitive. If the name contains uppercase characters, the Web application will be damaged when it is uploaded 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 sorting order of records. If you are using English, 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" next To The "Location Of The Text File" Text box and select php_test. SQL (which is in The assets folder Of The PHP Test Site ). Click Go at the bottom of the page ". In this case, the sample data is imported into the database. Do not disable phpMyAdmin because it will be used in the next section. Create a MySQL User account
The root Super User is used only when the management task in phpMyAdmin is executed, because it can erase all data. Once deleted, data cannot be recovered! MySQL does not have tools like Windows recycle bin or Mac waste bin. Therefore, the next task is to create a MySQL User account with limited permissions. Follow these steps to create an account that can only access the php_test database:
Click the icon like a small house in the upper left corner of the phpMyAdmin screen to return to the original welcome screen (see Figure 19 ). Click the "Privileges" tab at the top of the welcome page.
Note: many functions 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 go back to the welcome page and click the "Privileges" tab there.
Click "Add A New User" (near the lower half of the page ). In the "User Name" text box, type phptestuser. Select "Local" as "Host ". This will enter localhost in the text box next to it, specifying that the user can only access the local test environment. In the "Password" field, type a Password. in the next field, type the Password again. The rest of the page remains unchanged, and then click Go at the bottom of the page ".
The next screen will confirm that a new user has been added. The "Global privileges" section provides the user account with the same permissions for all databases. In 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 underline in the database name. In some environments, this underline can be used as a wildcard in MySQL, and the backslash here is used to ensure that the underline is used as a text character. However, this is an exception. Generally, a backslash should not be placed before the underline in the database, table, or column name.
On the next page, you can set user permissions for the selected database. For Web applications, only four permissions are required: SELECT, INSERT, UPDATE, and DELETE. Select them and click "Go:
Set SELECT, INSERT, UPDATE, and DELETE user permissions for Web applications.
You have 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.
Connect to 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 in the center of the page (see Figure 22) shows the display position of the result. Before viewing 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. On the Databases panel (select Window> Databases), click the plus sign (+) on the panel and select MySQL Connection ".
The "MySQL Connection" dialog box is displayed.
Enter connTest as the connection name. For "MySQL Server", type localhost.
If you use the default MAMP port on Mac, use localhost: 8889.
For "User Name", type phptestuser. In the "Password" field, type the Password you selected for the phptestuser account. For "Database", type php_test.
Note: You do not need to place a backslash before the underline. In the previous section, phpMyAdmin inserts a backslash (see Figure 20) because phpMyAdmin uses a query that allows wildcards.
Click "Test ".
Dreamweaver will try to connect to the database. If the connection fails, perform the following operations:
Check the server name, user name, and password. Check the settings of the folders that Dreamweaver uses to process dynamic pages (see specify a test server for Dreamweaver ). Verify that the Web and MySQL servers are running. Temporarily disable any firewall or security program. If the connection is valid, configure the security program to allow communication between Dreamweaver and MySQL. Click OK ". The "Database" panel displays the new connection. Expand the connTest connection and expand the "Tables" branch. You will see the comment table in the database, expand it to display the details of the table column. Click "real-time view. The dynamic text object in comments. php is replaced with the data retrieved from the database (see Figure 24 ).
Your PHP development environment and site have been set up. you can start developing PHP Web applications in Dreamweaver.
Follow-up work
This tutorial describes how to set up a PHP development environment, define a PHP site, and connect to a MySQL database. Defining websites, testing servers, and establishing MySQL connections are the basis for developing PHP Web applications in Dreamweaver. You are now ready to use PHP to develop dynamic websites in Dreamweaver.
There are many PHP development environments. here we will introduce Dreamweaver cs6,
It is better to write a PHP registry ticket for verification, and the code is easy to debug end,