由于实验室 Project 中需要用到PHP, 之前也没接触过 PHP, 因此把 编程入门 《Head Fist PHP & MySQL 》找来花了四五天快速过了一遍。
现在想把书中的系统东西总结一下,方便日后的查询。
chapter01 & chapter02 主要简单介绍了 PHP 以及 MySQL 数据库的基本语句,有基础的同学随便翻翻就懂了。
虽然简单,但是它仍然 构建出了一个 基本完整的网站的 框架, 这也是我觉得 Head First 系列很优秀的地方。
前两章主要大体介绍了 PHP 和 MySQL 数据库的基本操作,配套的书中在这两章中通过 PHP 和 MySQL 搭建了一个最简单的 WebSite。 为了练习英文我就用 英文写啦:
You can following the steps to finish this lab :
1. You need to install Apache, PHP, MySQL on you Server(Mine is Linux)
2. Create a new folder, name it Chapter01 or whatever, edit the following files in the folder:
/*** report.html ***/
Aliens Abducted Me - Report an Abduction Aliens Abducted Me - Report an Abduction
Share your story of alien abduction:
/*** style.css ***/
form label { display: inline-block; width: 225px; font-weight: bold;}
you can put these files in diffierent folders. that would be a good habit. I am so lazy so I put them together in one folder(Mine is cha01).
3. Create a database with the MySQL. User this database. Create a table in the database.
Use the command :
mysql -u root -p; #you can login in MySQL as root
create database headfirst; #create a database named headfirst;
use database headfirst; #use this database;
then you need to create a table with the following scripts:
CREATE TABLE aliens_abduction ( first_name varchar(30), last_name varchar(30), when_it_happened varchar(30), how_long varchar(30), how_many varchar(30), alien_description varchar(100), what_they_did varchar(100), fang_spotted varchar(10), other varchar(100), email varchar(50));
4. Now you have finish the HTML file on the Server, which will send to the client(Broswer) , and people will use this file to get access to your Server.
and you have created a database on the Server, which will store the data the from client all over the world.
Then what you need is to set a PHP file on the Server to handle the requests from the client and put the data in the requests into the database.
Now, you can see the PHP file on the Server is just like a bridge between the client and server.
/*** report.php ***/
Aliens Abducted Me - Report an Abduction Aliens Abducted Me - Report an Abduction
'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . ''; echo 'Number of aliens: ' . $how_many . ''; echo 'Describe them: ' . $alien_description . ''; echo 'The aliens did this: ' . $what_they_did . ''; echo 'Was Fang there? ' . $fang_spotted . ''; echo 'Other comments: ' . $other . ''; echo 'Your email address is ' . $email;?>
Then you have finished a basic WebSite. If you put it on to the internet, everyone can access it through the internet. Thats cool!