Introduction to...LOGIN

Introduction to PHP MySQL

Through PHP, you can connect and operate the database.
MySQL is the most popular open source database system used with PHP.
If you want to learn more MySQL knowledge, you can check out the MySQL tutorial on this site.

PHP What is MySQL

MySQL is a relational database (Relational Database Management System), this so-called "relational "can be understood as the concept of "table",

A relational database consists of one or several tables, such as a table as shown in the figure:

106.png


Header: The name of each column;

Column (row): A collection of data with the same data type;

Row (col): Each row is used to describe the specific information of a person/object;

value( value): The specific information of the row, each value must be the same as the data type of the column;

Key (key): Used to identify a specific person in the table \Object method, the value of the key is unique in the current column.


#The picture above shows a simple database table, allowing beginners to have a preliminary image in their minds. The following describes the characteristics of MySQL

MySQL is a database system used on the Web.

MySQL is a database system that runs on a server.

MySQL is ideal for both small and large applications.

MySQL is very fast, reliable, and easy to use.

The core program of MySql adopts complete multi-threaded programming.

MySQL supports standard SQL.

MySQL compiles on some platforms.

MySQL is free to download and use.

MySQL is developed, published and supported by Oracle Corporation.

MySQL is named after the company founder Monty Widenius's daughter: My.

PHP provides strong support for MySql. PHP provides a complete set of MySql functions and provides comprehensive support for MySql.

Data in MySQL is stored in tables. A table is a collection of related data, consisting of columns and rows.


Databases are very useful when storing information in categories. A company's database may have the following tables:

Employees: employee class table.

Products: Product table.

Customers: Customer form.

Orders: Company order form.


PHP + MySQL

The free MySQL database is usually used through PHP.

The combination of PHP and MySQL is cross-platform. (You can develop on Windows and apply on Unix platforms.)

Query

A query is an inquiry or request.

Through MySQL, we can query the database for specific information and get the returned record set.

Please see the following query (using standard SQL):

mysql> set names utf8;
mysql> SELECT name(column) FROM websites(database table name);
+--------------+
| name |
+---------------+
| Google |
| Taobao |
| php Chinese website |
| Weibo |
                                                                                                              ##Statement
set names utf8;
is used to set the database encoding so that Chinese can be displayed normally.

The above query selects all the data in the "name" column in the "websites" table.

Query statements are the basic operations for learning MySQL, which will be explained in detail on the following website. To learn more about SQL, please visit our SQL tutorial.

Download MySQL database

If your PHP server does not have a MySQL database, you can download MySQL for free here: http://www.mysql .com. You can also use software such as: WampServer, PhpStudy, etc., with its own MySQL database.


Facts About MySQL Database

One of the great features about MySQL is that it can be reduced to support embedded databases app. Perhaps because of this, many people think that MySQL can only handle small and medium-sized systems. In fact, MySQL is the de facto standard database for websites that support huge data and traffic (such as Friendster, Yahoo, Google).

This address provides an overview of companies using MySQL: http://www.mysql.com/customers/.


Distinguish between database and database management software

We usually call MySQL a database. In fact, the full name should be database management software, and a collection of data tables It's called a database. Therefore, a database management software can manage multiple databases, each database can have multiple data tables, and each data table can have multiple fields.

Next Section
<?php // 这段代码需要预先创建好数据库和表才能运行 $conn = mysqli_connect($servername,$username,$password); // 获取连接 if($conn){ //判断是否连接 mysqli_select_db($conn,"db_name"); // 选择一个数据库 mysqli_query($conn,"set names utf8"); // 查询输出要使用utf8的编码格式,避免乱码 $sql = "select * from product;"; // 查找到数据库的product表() $result = mysqli_query($conn,$sql); // 从键连获取到数据库的字表 while($row = mysqli_fetch_array($result,MYSQL_ASSOC)){ // MYSQLI_ASSOC返回键值形式数组 echo $row["需要输出的表中列的名称"]; } mysqli_free_result($result); // 释放内存在 mysqli_close($conn); // 关闭连接 echo "成功"; }else{ echo "失败"; }; ?>
submitReset Code
ChapterCourseware