[PHP] HeadFirst-PHP & MySQL (Chapter 2 summarizes) manual operations on a large amount of data is a very tedious task, so you need a database to help you manage data.
As a mainstream database, MySQL uses the SQL language. Generally, you can use the MySQL terminal and phpMyAdmin graphical tool to manage input. phpMyAdmin can be found on the local page of wnmp.
Generally, the user name for the first Test is root, and the password for the first Test database is password. MySQL command
Create database example; CREATE a DATABASE example
USE example; select to USE example database
Create table users (
Name varchar (30 ),
Email varchar (50 ),
)
The users table created in the example database contains two columns: name and email. the varchar types are 30 and 50, respectively.
Insert into users (name, email)
VALUES ('Jack', 'jacksemail @ gmail.com ')
Insert data to the users Table. the name corresponds to 'Jack', and the email corresponds to 'jacksemail @ gmail.com'
SELECT * FROM users
Request data from all columns in the users table
SELECT name FROM users
Request data in the name column of the users table
SELECT name, email FROM users
Request data in the name and email columns of the users table
MySQL commands in PHP
Mysqli_connection ('database location ', 'database username', 'database password', 'database name ')
Database location = domain name, IP address or localhost
Database username = root (MySQL default)
Database password = password (MySQL default)
Database name = example (custom database name)
Mysqli query (databaseconnect, query );
Use a database connection and a query string to complete SQL queries
My close (databaseconnect)
Close connection
Summary
This chapter describes how to create a database table, insert data, and query data in the database, and connect to the database, insert data, and close the database in php.