Trigger
Delimiter $$ (set $$ as statement Terminator)
Cases:
Delimiter $$
Create trigger Jiaobanfei after update on User1
For each row
Begin
Update User2 set age=age+ (Old.num-new.num);
Update User2 set num=num+1;
End
$$
Delimiter
Old.age-new.age
To delete; drop trigger Jiaobanfei;
Update user1 set num=num-4 where id=1;
NOTE: 1. Triggers cannot have the same name
2, currently MySQL only supports a class of events set a trigger
Within the trigger, get the data that triggered the trigger change:
Use new and old within the trigger to complete
Old: Data before the time occurs
NEW: The data after the event occurs on the listener table
Event is insert, cannot use old
Event is delete, cannot use new
If a trigger is composed of multiple SQL statements:
should; 1. Statement block (Begin,end) to identify statement blocks
2, Statement Fast statement requires a separate statement terminator, semicolon
Command line: Because a semicolon is used within a trigger program as a statement terminator, the command line client
When a semicolon is encountered, it should be understood as the end of the statement in the trigger program, rather than the end of the statement that created the trigger.
This should be done by modifying the command line's statement terminator to achieve
Delimiter statement can complete SET statement terminator
Test: INSERT into on duplicate key update (if primary key is duplicated when inserting data, modify operation)
Replalce
PHP operates MySQL client with three
Msyql,mysqli,pdo
Test whether a function is available
Var_dump (function_exists (' mysql_connect '));
Common: show,desc,select return result sets
Insert,update, DELETE Returns a Boolean value
ASSOC: Associative array
row; index Array
Array: Mixed array
Fetch can only get one, but can automatically move, the result set of the record pointer, with the loop structure, complete the operation of all the data
MySQL Error:
Get the error message;
Mysql_error (); Error message
Mysql_errno (); Error number
1. Get the amount of data in the result set
Mysql_num_rows (Result set)
Check
2, after the operation, the number of rows affected
Mysql_affected_rows ();
Applicable to additions and deletions to change
3. Get the value of the latest autogrow field, usually the ID primary key
MYSQL_INSERT_ID ();
4. If resources are used, resources should be released
Mysql_free_result (result set);
A resource that needs to be freed; a composite type of data (array, object), resource
Just unset the variables.
mSQL database triggers and connections to MySQL common functions