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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles