Home Backend Development PHP Tutorial PHP&MYSQL review outline_PHP tutorial

PHP&MYSQL review outline_PHP tutorial

Jul 14, 2016 am 10:07 AM
amp mysql php one only review data integer type grammar

PHP&MYSQL review outline 1

1. PHP syntax

◆ Data type

PHP has only three basic data types: integers, floating point numbers (or real numbers, double precision numbers) and strings. Strings can use single quotes and double quotes, but they have different meanings: variables can only be used within double quotes.

◆ Variables

Add "$" in front of the variable. When using a variable, you do not need to specify (or define) the type of the variable in advance. Different types of data can be assigned to the same variable. But if you want to use global variables, you must use global instructions (or add them to the $GLOBALS[] array). To use static variables, use static instructions.

◆ Array

Using an array does not require specifying its type and size, it can be used directly. Elements of the same array can have different data types.

◇ Scalar array

Use the following assignment statement to generate a scalar array:

 $a[0]=100;
​$a[1]="Hello";
​$a[2]=23.4;

If the subscript is omitted, the subscript values ​​will be automatically arranged in order.

◇ Associative array

Use the following assignment statement to generate an associative array:

 $students[name]= 'Zhang San';
​$students[age]= 20;
​$students[tel]= '65032905-8097';

When accessing the database, a record can be used as an associative array, with the field name in square brackets.

◆ Operator

Generally retains the operators of C language. Added string concatenation character "." (use "->" when accessing object members). Added "=>" operator, used to assign initial value to array. In addition, logical AND ("&&") and logical OR ("||") can also be used with "and" and "or", and logical exclusive OR "xor" is added.

◆ Basic sentences

It is required to master the if-else statement, switch-case statement, for statement, while statement, do-while statement, continue statement, and break statement. require statement and include statement, used to insert a disk file. The difference is: if used in a conditional statement, include only inserts the file when the condition is met, while require always inserts. The format is:

include("file name");
require("file name");

◆ Definition and use of functions

Use function to define a function without specifying the function type and parameter type.

Function function name (parameter 1, parameter 2,...)
{ Statement 1;
Statement 2;......
}

It is allowed to add "&" before the parameters so that the parameters can transfer data in both directions. It is also allowed to assign default values ​​to parameters.

2. MYSQL syntax

Numeric type

Column type

Amount of storage required

TINYINT

1 byte

SMALLINT

2 bytes

MEDIUMINT

3 bytes

INT

4 bytes

INTEGER

4 bytes

BIGINT

8 bytes

FLOAT(X)

4 if X < = 24 or 8 if 25 < = X < = 53

FLOAT

4 bytes

DOUBLE

8 bytes

DOUBLE PRECISION

8 bytes

REAL

8 bytes

DECIMAL(M,D)

M bytes (D+2, if M < D)

NUMERIC(M,D)

M bytes (D+2, if M < D)

Date and time types
Column type

Amount of storage required

DATE

3 bytes

DATETIME

8 bytes

TIMESTAMP

4 bytes

TIME

3 bytes

YEAR

1 byte

String type
Column type

Amount of storage required

CHAR(M)

M bytes, 1 <= M <= 255

VARCHAR(M)

L+1 bytes, where L <= M and 1 <= M <= 255

TINYBLOB, TINYTEXT

L+1 bytes, here L< 2 ^ 8

BLOB, TEXT

L+2 bytes, where L< 2 ^ 16

MEDIUMBLOB, MEDIUMTEXT

L+3 bytes, here L< 2 ^ 24

LONGBLOB, LONGTEXT

L+4 bytes, where L< 2 ^ 32

ENUM('value1','value2',...)

1 or 2 bytes, depending on the number of enumeration values ​​(maximum 65535)

SET('value1','value2',...)

1, 2, 3, 4 or 8 bytes, depending on the number of set members (up to 64 members)

1. Create a new database

CREATE DATABASE Database name

2. Display database

SHOW DATABASES

3. Open the database

USE database name

4. Display the tables in the database

SHOW TABLES

5. Display table structure

DESCRIBE table name or SHOW COLUMNS FROM table name

6. Create table

CREATE TABLE Table name (field name Data type (data size) [NOT NULL][PRIMARY KEY[AUTO_INCREMENT]],...)

7. Modify table

A. Add new domain

Format: ALTER TABLE table name ADD COLUMN field name data type (data size) NOT NULL...

B. Modify domain

Format: ALTER TABLE table name CHANGE COLUMN field name field definition

C. Delete domain

Format: ALTER TABLE table name DROP COLUMN domain name

8. Delete table

Format: DROP TABLE Table name

9. Select query

Format: SELECT Domain name [AS Domain alias]...FROM Table name [WHERE Condition][GROUP BY...][HAVING...][ORDER BY...]

10. Add a single record

insert into table name (field 1, field 2,...) values ​​(value 1, value 2,...)

11. Add multiple records

insert into table name (field 1, field 2,...) select field from table where condition;

12. Update record

update table name set field name = new value where condition

13. Delete records

delete from table name where condition


3. Examples

1. IF…ELSE program

if_else.php

Please enter your gender:

Male

Female

if ($gender=="woman")

echo "

Hello, Miss

";

else

echo "<>Hello Sir

";

?>

2. IF…ELSEIF…ELSE program

Simple Calculator

Operator 1:

Operator 2:

What operation do you want to perform?

add

minus

Multiply

except


Result:

Equals

if ($operation == "Add")

{$x = $num1 + $num2;

print $x;}

elseif ($operation == "Minus")

{$x = $num1 - $num2;

print $x;}

elseif ($operation == "Multiple")

{$x = $num1 * $num2;

print $x;}

elseif ($operation == "except")

{$x=$num1/$num2;

print $x;}

else

print $x;

?>


3. for loop program

Calculate the value of 1+2+…+100

$sum=0;

for ($i=1; $i<=100; $i++) //Enter the loop

{

$sum+=$i; //Execute once to add $sum to $i

}

echo $sum; //Display results

?>

4. while program

while.php

$sum=0;

while ($i<=100)                                                       

{

$sum+=$i;

$i++;

};

echo $sum;

?>

5. do … while program

do_while.php

What is the upper limit of summation?

$sum=0; $i=1;

do {                                                                  

$sum+=$i;

$i++;

}

while ($i<=$up);                               

echo "Start from 1 and add to".($i-1);

echo "
";

echo "The sum is".$sum;

?>

6. Function routine

function cal ($cal_nu)                                              

{

$cal_sqr=$cal_nu*$cal_nu;

$cal_cub=$cal_nu*$cal_nu*$cal_nu;

return array($cal_sqr, $cal_cub);

}

?>

Calculate squares and cubes

Please enter a number

list($sqr, $cub) = cal($nu_input);

echo $nu_input; echo "The square of "is:"; echo $sqr;

echo "
";

echo $nu_input; echo "The cube of " is: "; echo $cub;

?>

7. Create data table

mysql_connect("localhost","s990402","zq");

mysql_select_db("s990402");

$str="CREATE TABLE students(

id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

name CHAR(10),

age INT,

tel VARCHAR(20),
​addr VARCHAR(30)

)";
$result=mysql_query($str);

if($result)
echo "Data table "students" created successfully!";
else

echo "Data table creation failed!";

?>
8. Add record


$cn=mysql_connect("localhost","s990402","zq");
mysql_select_db("s990402",$cn);
$ins=mysql_query("INSERT INTO students(nam,age,tel,addr)

VALUES('$nam',$age,'$tel','$addr')",$cn);

if($ins)

echo "New records have been added to the database.";

else
echo "Record addition failed.";
?>

9. Browsing history





mysql_connect("localhost","s990402","zq");
mysql_select_db("s990402");
$q=mysql_query("SELECT * FROM students ORDER BY age DESC");
while($a=mysql_fetch_array($q))
  print "
    "
?>
姓名年龄电话住址
$a[name]$a[age]$a[tel]$a[addr]

10. 删除记录(本程序文件名为del.php)

$cn=mysql_connect("localhost","s990402","zq");
mysql_select_db("s990402",$cn);
if($id>0) mysql_query("DELETE FROM students WHERE id=$id",$cn);
?>





$q=mysql_query("SELECT * FROM students ORDER BY age DESC",$cn);
while($a=mysql_fetch_array($q))
 print "
   
   "
?>
姓名年龄电话住址
删除$a[nam]$a[age]$a[tel]$a[addr]

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477886.htmlTechArticlePHPMYSQL复习提纲1 一、 PHP语法 ◆ 数据类型 PHP 只有整数、浮点数(或称实数、双精度数)和字符串三种基本数据类型。字符串可用单引号和...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

CakePHP Useful Resources CakePHP Useful Resources Sep 10, 2024 pm 05:27 PM

The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.

See all articles