Common skills in PHP programming

Source: Internet
Author: User
Tags empty connect mysql php file php and php and mysql table name mysql database
Programming | Skills PHP programming Skills Four

1. Configure PHP file directory

As a scripting language for server-side interpretation execution, PHP programs are placed in a directory accessible to a server, and can generally be configured by modifying Apache Httpd.conj, such as our sentence in this document:

alias/test/"d:/phpwebsite/php/" then in the browser-side input: "Http://localhost/test/+PHP file name" can access the d:/phpwebsite/php/under the php file ; Visible the line is simply an alias for the directory where the php file is stored.

Second, you can also specify the DocumentRoot path to store the directory of server files, in Httpd.conj find the following two lines, where the path can be arbitrarily specified, your PHP files can also be placed in the directory, the server can also run them, such as "http:// localhost/+php file name ".

In general, the PHP file in the same place is better, you can easily manage, and other files in another place.

DocumentRoot "c:/usr/bin/html/"

2. index files for server-side directories
In Httpd.conj, there is one line:
DirectoryIndex index.html

The row specifies that the directory defaults to open file as index.html, and when a directory is accessed, the server automatically finds index.html and, if not, displays a list of all the files in the directory, and the default open file can be changed to something else. such as index.php3 and so on, but perhaps we have a lot of directories, whether it is to store pictures, text, and other information, or to store PHP files or other files directory, we do not want users to see the directory in the list of files, in the Httpd.conj A. htacess file is specified in the file, which produces a directory index file, for example, we use WordPad to create a. htacess file:

#. Htacess #
DirectoryIndex error_open.php
Create an error warning file again:
# error_open.php #


The error_open.php is a permission error warning file that places the 2 files under all protected directories and automatically turns to execute error_open.php when the user attempts to open the directory, displaying an error warning.

3. Directory Deletion clever implementation
We know that there is a rename () function in PHP4 For/win32 that can support renaming a directory/file, such as:
Rename (OldPath, NewPath)//OldPath as the original path of the file or directory;
NewPath is the new defined path;

Realize the OldPath renamed to NewPath.

There is no function to delete the directory/file in the PHP4, how to delete it? As we know, there is a row in php.ini for the temporary file directory configuration line used to complete the HTTP upload operation:
upload_tmp_dir=;

PHP4 support the configuration of the temporary directory (PHP3 not supported), when the upload operation is completed, automatically empty the temporary directory, OK, with it we can skillfully implement file/directory deletion, such as setting: Upload_tmp_dir= "d:/phpwebsite/php/tmp/";
To delete a directory path, perform:

Tmp= "d:/phpwebsite/php/tmp/;"
Rename (path, TMP)
?>

After the file or directory path is renamed TMP, all files/directories under the TMP directory are automatically cleared and the deletion is completed.

4. Quickly establish MySQL database table

PHP and MySQL database to achieve a perfect combination, on the Web page, such as in the Forum or bookstore published works of new users, we want to write his message online to the database, often in the corresponding database for the user to create a new data table. Win32 to create a new MySQL empty database is very simple, as long as the "/mysql/data/" directory to create a folder, such as: "/usrinfo/", you can. Adding a new table to the library can be accomplished by using the following program:

# connect.mysql--Connection Database #
Connection = mysql_connect ();
mysql_select_db ("Usrinfo", connection);
?>
# make.php--establishes the following data table with user name as table name #
Call Connect.mysql
Require ("Connect.mysql");
Check for data tables with user name as table name?
query= "SELECT COUNT (*) from Usrname";
Result=mysql_db_query (query);
Does not exist then creates, if exists is the old user;
if (! Result) {
mysql_query ("
CREATE TABLE Usrname (
ID tinyint (6),
Title text,
Body Longtext,
Dateof date;
Timeof time;
) or Die (Mysql_error ());
}
To insert a new data section into a datasheet
?>

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.