Php Mysql 简明教程
PHP & MySQL - Environment Setup
为了开发和运行 PHP 网页,您的计算机系统上需要安装三个重要组件。
In order to develop and run PHP Web pages, three vital components need to be installed on your computer system.
-
Web Server − PHP works with virtually all Web Server software, including Microsoft’s Internet Information Server (IIS) but most often used is Apache Server. Download Apache for free here − https://httpd.apache.org/download.cgi
-
Database − PHP works with virtually all database software, including Oracle and Sybase but most commonly used is MySQL database. Download MySQL for free here − https://www.mysql.com/downloads/
-
PHP Parser − In order to process PHP script instructions, a parser must be installed to generate HTML output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your computer.
PHP Parser Installation
在您进行之前,在计算机上确保设置好适当的环境,以使用 PHP 开发您的网络程序非常重要。将以下 php 文件储存在 Apache 的 htdocs 文件夹中。
Before you proceed, it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP. Store the following php file in Apache’s htdocs folder.
phpinfo.php
<?php
phpinfo();
?>
在您的浏览器的地址框中输入以下地址。
Type the following address into your browser’s address box.
http://127.0.0.1/phpinfo.php
如果这样做会显示一个页面,显示您的 PHP 安装相关信息,则表示已正确安装了 PHP 和 Web 服务器。否则,您必须按照给定的程序在计算机上安装 PHP。
If this displays a page showing your PHP installation related information, then it means you have PHP and Webserver installed properly. Otherwise, you have to follow the given procedure to install PHP on your computer.
本部分将指导您在以下四个平台上安装和配置 PHP −
This section will guide you to install and configure PHP over the following four platforms −
Apache Configuration
如果您使用 Apache 作为 Web 服务器,那么本部分将指导您编辑 Apache 配置文件。
If you are using Apache as a Web Server, then this section will guide you to edit Apache Configuration Files.
Check here − PHP Configuration in Apache Server
PHP.INI File Configuration
PHP 配置文件 php.ini 是影响 PHP 功能的最后一种直接方法。
The PHP configuration file, php.ini, is the final and immediate way to affect PHP’s functionality.
在此处查看 − PHP.INI File Configuration
Check here − PHP.INI File Configuration
Windows IIS Configuration
要在 Windows 机器上配置 IIS,您可以参考随 IIS 一起提供的 IIS 参考手册。
To configure IIS on your Windows machine, you can refer your IIS Reference Manual shipped along with IIS.
Install MySQL Database
当然,您将需要最重要的实际运行数据库,其中包含您可以查询和修改的表。
The most important thing you will need, of course is an actual running database with a table that you can query and modify.
-
MySQL DB − MySQL is an open source database. You can download it from MySQL Official Site. We recommend downloading the full Windows installation.
-
In addition, download and install MySQL Administrator as well as MySQL Query Browser. These are GUI based tools that will make your development much easier.
-
Finally, download and unzip MySQL Connector/J (the MySQL JDBC driver) in a convenient directory. For the purpose of this tutorial we will assume that you have installed the driver at C:\Program Files\MySQL\mysql-connector-java-5.1.8.
-
Accordingly, set CLASSPATH variable to C:\Program Files\MySQL\mysql-connector-java-5.1.8\mysql-connector-java-5.1.8-bin.jar. Your driver version may vary based on your installation.
Set Database Credential
当我们安装 MySQL 数据库时,它的管理员 ID 设置为 root ,并提供设置密码的选项。
When we install MySQL database, its administrator ID is set to root and it gives provision to set a password of your choice.
使用 root ID 和密码,您可以创建另一个用户 ID 和密码,也可以为您的 JDBC 应用程序使用 root ID 和密码。
Using root ID and password you can either create another user ID and password, or you can use root ID and password for your JDBC application.
有各种数据库操作,例如数据库创建和删除,这需要管理员 ID 和密码。
There are various database operations like database creation and deletion, which would need administrator ID and password.
对于 JDBC 教程的其余部分,我们将使用 MySQL 数据库, guest 为 ID, guest123 为密码。
For rest of the JDBC tutorial, we would use MySQL Database with guest as ID and guest123 as password.
如果您没有足够权限创建新用户,那么您可以请求数据库管理员 (DBA) 为您创建用户 ID 和密码。
If you do not have sufficient privilege to create new users, then you can ask your Database Administrator (DBA) to create a user ID and password for you.
Create Database
要创建 TUTORIALSPOINT 数据库,请执行以下步骤 −
To create the TUTORIALSPOINT database, use the following steps −
Step 1
打开 Command Prompt 并更改到安装目录,如下所示 −
Open a Command Prompt and change to the installation directory as follows −
C:\>
C:\>cd Program Files\MySQL\bin
C:\Program Files\MySQL\bin>
Note − mysqld.exe 的路径可能因系统上 MySQL 的安装位置而异。您还可以查看有关如何启动和停止数据库服务器的文档。
Note − The path to mysqld.exe may vary depending on the install location of MySQL on your system. You can also check documentation on how to start and stop your database server.
Create Table
要创建 Employees 表中 TUTORIALSPOINT 数据库,请执行以下步骤 −
To create the Employees table in TUTORIALSPOINT database, use the following steps −
Step 1
打开 Command Prompt 并更改到安装目录,如下所示 −
Open a Command Prompt and change to the installation directory as follows −
C:\>
C:\>cd Program Files\MySQL\bin
C:\Program Files\MySQL\bin>
Create Data Records
最后,在 Employee 表中创建一些记录,如下所示 −
Finally you create few records in Employee table as follows −
mysql> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
Query OK, 1 row affected (0.05 sec)
mysql> INSERT INTO Employees VALUES (101, 25, 'Mahnaz', 'Fatma');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO Employees VALUES (102, 30, 'Zaid', 'Khan');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO Employees VALUES (103, 28, 'Sumit', 'Mittal');
Query OK, 1 row affected (0.00 sec)
mysql>
如需全面了解 MySQL 数据库,请学习 MySQL Tutorial 。
For a complete understanding on MySQL database, study the MySQL Tutorial.
现在,您可以开始尝试使用 PHP 了。
Now you are ready to start experimenting with PHP.