20161021 (php Basic syntax)

Source: Internet
Author: User
Tags echo date set time

Morning:

Database summary:

1. Create a database

Create DATABASE name

Deleting a database

Drop database name

2. Create a table

CREATE TABLE Table name

(

Column name type (length) from the growth primary key is not empty,

)

Self-growth: auto_increment

Primary Key: PRIMARY Key

Non-empty: NOT NULL

Foreign key: foreign key column name references table name (column Name)

Delete a table

DROP table Name

3.CRUD operation

Insert into table name values (value)

Insert into table name (column Name) values (value)

Delete from table name where condition

Update table name set column name = value WHERE condition

SELECT * FROM table name

Select Column name from table name

SELECT * FROM table name where condition

SELECT * FROM table name where Condition 1 or Condition 2

SELECT * FROM table name where column name like '% value% '

SELECT * FROM table name where column name between A and B

SELECT * FROM table name where column name in (value)

SELECT * FROM table name limit n,m

SELECT * FROM table name order BY column name Desc

SELECT * FROM table name Group BY column name having condition

Select Count (*) from table name

Select Sum (column name) from table name

Select Avg (column name) from table name

Select Max (column name) from table name

Select min (column name) from table name

Select DISTINCT column name from table name

Advanced Query:

1. Connection Query

SELECT * FROM table 1, table 2 where connection conditions

SELECT * FROM table 1 join table 2 on join condition

2. Joint queries

Select Column name from table 1

Union

Select Column name from Table 2

3. sub-query

Unrelated subqueries

Subqueries are not related to parent queries, and subqueries can be executed separately

SELECT * FROM table where column = (select column from Table)

Related sub-query

Subqueries and parent queries are related to each other, and subqueries need to use the contents of the parent query

PHP Basic Syntax:

PHP tags <?php content?, All content is written in the label

Comment Syntax:

// Single-line Comment

/* Multi-line Comment * /

Output syntax

Echo "hello";

Echo "world", "dhakj";// multiple strings can be output

Print "aaa";// only one string can be output

Print_r ();// Print Array

var_dump ();// output variables and types

Variable definition

Data type, weakly typed language

$a = "hello";

$hello = "world";

echo $ $a;// variable variable, The output is the world

Type conversions

$a = 6;

$b = (string) $a; Type conversions

Settype ($a, "string"); In addition the way Settype (variable, "type")

Var_dump ($a); no return value, return True or False: True,false

Operators and expressions

Subtraction to take the remainder

$a = 6;

$b = 7;

$c = $a% $b;

Var_dump ($c); Output 0

Logical operations

And

$a = true;

$b = false;

$c = $a | | $b;

Var_dump ($c); Output True

Or

$a = true;

$b = false;

$c = $a && $b;

Var_dump ($c); Output False

Non -

$a = true;

$b = false;

Var_dump (! $a); Output False

$a = "hello";

$b = "world";

$c = $a. $b;// stitching a string with a dot (. the other languages are all +

Echo $c; output HelloWorld

$a = 8;

@ $c = $a/$b;// Error Suppressor

Echo $c;

Error messages in PHP

Notice: Reminders (general Reminders that some functions are removed in the next release, can be suppressed)

Warning: warning (can be suppressed)

Error: wrong (cannot Suppress)

Ternary operators

$a = 4;

$b = 5;

echo $a = = $b? " Equal ":" not equal "; (condition?") The return value ":" that satisfies the condition does not meet the return value of the condition ")

Statement:

Order

$a = 5;

$b = 6;

Branch

if ($a = = $b)

{

Echo "equal";

}

Else

{

Echo "unequal";

}

Switch ($a)

{

Case 4:

Echo "4444";

Break

Case 5:

Echo "55555";

Break

Case 6:

Echo "66667";

Break

Default

Echo "000000";

}

Cycle

For ($a =0; $a <10; $a + +)

{

Echo $a;

}

For () (mainly used for Traversal)

{

}

each

{

}

While (true) (after the condition is judged)

{

Echo "aaa";

}

Do (judge condition after first Execution)

{

}

While ()

?>

Afternoon:

PHP functions:

<?php

Function four elements

return type function Name argument list function body

Function Show ()

{

}

The simplest way to define a function

function Show ()

{

Echo "hello";

}

Show ();

function with parameters

Function Show ($a)

{

Echo $a;

}

Show ("hello");

Functions that have return values

Function Show ()

{

Return "aaaaa";

}

Echo Show ();

Functions with default values

Function Show ($a = "hello")

{

Echo $a;

}

Show ("ceshi");

Functions with variable parameters

Function Show ()

{

Var_dump (func_num_args ());

Func_get_args () Get the parameter list

Func_num_args () Gets the number of arguments

$attr = Func_get_args ();

$sum = 0;

For ($i =0; $i <count ($attr); $i + +)

{

$sum = $sum + $attr [$i];

}

Return $sum;

}

Echo Show (1,2,3,4);

Common functions

echo Rand (0,10); Generate random number void: null (minimum, Maximum)

Date Time

Echo Time (); Takes the current time, returns the Unix timestamp, the number of seconds from January 1, 1970 0:0:00 to the current time

echo Date ("y-m-d h:i:s"); Format Date Time

Set time zone: php.ini in PHP search for Date.timezone and replace the contents of the Equals sign with etc/gmt-8

echo Strtotime ("2016-3-4 12:09:10"); Convert a string to a timestamp

String functions

$a = "hello|world|ni|hao";

Echo strlen ($a); Take the length of the string

echo strcmp ("Hello", $a); Compares two strings, equals returns 0, is case-sensitive

echo strcasecmp ("Hello", $a); Compares two strings, equals returns 0, is case-insensitive

Echo Strtolower ("Hello"); Turn a string into lowercase

Echo Strtoupper ("hello"); Turn a string to uppercase

Var_dump (explode ("|", $a)); Splits a string, returns an array

$attr = array ("aa", "bb", "cc", "dd");

Echo Implode ("%", $attr); Stitching strings

echo substr_replace ($a, "* * *", 0,5); Replaces a string at the specified position

The first parameter is the string to replace

The second argument is the replacement string

The third parameter is the start position

The fourth parameter is a replacement length

echo str_replace ("|", "?", $a); Find replacements

The first argument is the string to find

The second argument is the string to replace

The third parameter is the string to be manipulated

$s = "2016 new Year's Day holiday schedule";

echo str_replace ("new year's day", "<mark> New Year </mark>", $s);

echo substr ($a, 0,5); Intercepts a string at a specified position

/* $s = "";

For ($i =0; $i <10; $i + +)

{

$s = $s. $i. ",";

}

$s = substr ($s, 0,strlen ($s)-1);

Echo $s; * *

About string Definitions

/* $a = "test";

$s = "hello{$a}world";

$str = ' HelloWorld ';

Echo $str; * *

/* $z 1 = "p001";

$z 2 = "zhang san";

$z 3 = "male";

$z 4 = "2000-1-2";

$z 5 = "0904";

$sql = "insert into info values ('".) $z 1. "', '". $z 2. "', '". $z 3. "', '". $z 4. "', '". $z 5. "')";

$sql = "insert into info values (' {$z 1} ', ' {$z 2} ', ' {$z 3} ', ' {$z 4} ', ' {$z 5} ')";

Echo $sql; * *

Z difference:

1. Single quotation marks do not resolve escape characters and the contents are output As-is

2. Single quotes do not parse variables

/* $s = <<<a

<span style= "color:red" > Hello </span>

A

Echo $s; * *

?>

20161021 (php Basic syntax)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.