One-step PHP installation

Source: Internet
Author: User
I used ASP for writing. Now I want to turn it around. php is good. It is not difficult for people who are familiar with code to turn it around!
From setting up the environment, familiarizing myself with the syntax, connecting to the database, and backing up and restoring data, I hope it will be ready in one step!
1. Establish the environment
Of course, the PHP environment selects a free combination set of Apache + PHP + MySQL + phpMyAdmin. Apache is a web server, MySQL is a free database, and phpMyAdmin is a free MySQL database management software. It is a PHP webpage.
The Apache + MySQL environment is difficult to set up. I am a lazy user. I chose easyphp integrated PHP environment. All the above components are available and all are configured, after installation, you can use it. I am looking for this is 1.8, the sky, huajun have download, support Chinese language, address to give a: http://www.skycn.com/soft/17714.html
After the setup, we can access it through 127.0.0.1. The default web directory is the WWW directory under the easyphp installation directory. Just put the Web file here.
2. Syntax
PHP code embedded web pages are similar to ASP, which are server-side script code. After the explanation is executed, the static Web page is returned to the client! The embedding method is as follows:

<? PHP
// PHP code
?>


The output uses the echo function. The statement ends with a semicolon, for example:

Echo "Hello! ";


Create a new file named index. php and enter

<? PHP
Echo "Hello! ";
?>


Save it to WWW and try again. OK
The code for connecting to the database is as follows:

1 <? PHP
2 $ conn = mysql_connect ('127. 0.0.1 ', 'root ','');
3 if (! $ Conn ){
4 die ('could not connect: '. mysql_error ());
5}
6 mysql_select_db ("Shop ");
7 $ exec = "select * from user ";
8 $ result = mysql_query ($ Exec );
9 While ($ rs = mysql_fetch_object ($ result ))
10 {
11 echo "username:". $ RS-> User. "<br> ";
12}
13 mysql_free_result ($ result );
14 mysql_close ($ conn );
15?>

$ Conn defines a variable, mysql_connect ('2017. 0.0.1 ', 'root', '') creates a database connection, the database administrator root, and the password is empty. Of course, the actual password should not be blank. After easyphp is installed, the default value is null.
Die indicates the output when the condition is not met. The mysql_error () function outputs the current error and the path of the error file. Click "." To connect the string.
Mysql_select_db ("Shop") sets the database to be connected. shop is the database name.
"Select * from user" database query statement: queries all fields in the User table. $ result = mysql_query ($ Exec) returns the query result to the variable $ result.
Mysql_fetch_object () assigns $ result to $ RS as an object, which is equivalent to a record set.
Echo "username:". $ RS-> User. "<br>" cyclically outputs the user field in the User table, which is accessed by "->"
Mysql_free_result ($ result) releases the memory occupied by $ result
Mysql_close ($ conn) closes the database connection
Of course, we can't see the effect now. The database has not been created yet. In easyphp, open phpMyAdmin, create a database shop, and create a table user. Set the appropriate types and lengths for the two field IDs and users, save. Enter a few more data items!
Now copy the connection code above to index. php and save it. Open the browser and check that the data is displayed!
3. Data Backup and Restoration
MySQL is a non-file-tested database, and direct backup of files is not acceptable, and most tools are backed up through the command line. I found a PHP version of phpmybackuppro, which can be found after searching on the Internet, upload a Chinese version:
Click to download: phpmybackuppro.v.2.1.rar
Create a directory named Bak under WWW, decompress the file to this directory, and access it through 127.0.0.1/Bak.
Set the MySQL user name and password in settings, and then select backup in backup. When restoring, click Import in "import.
Of course, what if we want to change the location, for example, we want to import data to the customer's machine?
It's easy to install phpmybackuppro on the customer's machine, copy files under the Bak \ export directory to the customer's machine, use phpMyAdmin to create a database with the same name, and log on to phpmybackuppro, similarly, click Import in "import.
This is the rule of lazy people: Make good use of tools.

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.