1.php introduction
- php is a back-end language. Is a server language. Run on the server side
- PHP is the suffix of PHP. We can understand the code
- The main goal is to allow web developers to quickly write dynamic page numbers
2. Basic grammar
- php can be placed anywhere in the document. With <? php starts with? > ending.
<?php #Here is the code ?>
- PHP statements end with a semicolon.
3. Notes
<?php // Single-Line Comments # Single-Line Comments /* multiline comment */ ?>
4. Variables
<?php // Solve the problem of garbled code header('Content-type:text/html;charset=utf-8') // Define variables $name = 'Zhang San'; // output echo $name; ?>
Variable rule
- The variable starts with the $sign, followed by the variable name
- Variable names must start with letters or underscores
- Variable names cannot start with numbers
- Variable names are case sensitive
- Variable names can only contain alphanumeric underscores
php output
- echo – can output more than one string
- print - returns 1 when the output is successful and 0 when the output fails
- var_dump() – the function is used to output variables and display the structured information of variables
5.php data type
<?php $num = 234; var_dump($num); // Integer int(234) $num1 = 234.1; var_dump($num1); // Floating point number float(234.1) $num2 = ture; var_dump($num2) // bool(true) ?>
6.PHP array
Array stores multiple values in a variable
Array creation method 1: stay PHP In the array, the value stored in the element can be any data type $arr[0] = 123; $arr[1] = 23.23; $arr[2] = 'hello' $arr[3] = true ergodic for($i=0;i<count($arr).length;$i++){ echo '<br>'.$arr[$i] } Mode 2: $arr = array('hello','hi')
7.PHP functions
<?php function test($num1,$num2){ $res = $num1+$num2; return $res; } ?>
8.PHP objects
An object is a data type that stores data and information about how data is processed
In PHP, objects must be explicitly declared
The class of the object must be declared, using the class keyword. A class is a structure that contains properties and methods
<?php calss Car { public $name; public $age; public function speak($str){ echo 'What is this'.$str; } } // Instantiate object $p1 = new Person(); $p1->name = 'Xiaobai' $p2->age = 24; $p1->speak('Zhang San') echo $p1->name; ?>
(point) is a splice
9. Interaction between PHP and the preceding paragraph
PHP receives front-end data
$_GET['Parameter name'] $_POST['Parameter name'] Chinese solution for request parameters header('Content-type:html;charset=utf-8');
10. Database
Concept: database is a warehouse organized, stored and managed according to data structure.
Warehouse: Warehouse
Table: a warehouse is divided into many parts. I really want to class
Fields: properties like classes
int ---> Integer type varchar ---> String type blob ---> Binary type date ---> Date type
10.1 common databases
Relational database:
oracle , mysql , SQLServer , DB2 , sybase
Non relational database
Redis , HBAse , CouchDB , MongoDB
Use of MySQL
Utility: phpstudy. Click mySQL manager and select mySQL front to enter the SQL editor
Open a library: use mydb
Create table:
create table students( sex char(4) not null; name varchar(8) not null; )
- Add a record
insert into book(username,userpass) value('Zhang San','123)
- delete
delete from book where username='Zhang San'
- check
select * from book where username='Zhang' and usersex='male'
- change
update book set usersex='female' where username='Zhang San'
10.2 PHP link Mysql
Connect to database: mysqli_connect();
Syntax: mysqli_conncet(servername,username,password,dbname)
Parameters:
- servername: Specifies the name of the server to be connected: the default is' localhost:3306 ';
- Password: specify the password used for login;
- dbname: indicates the database name