


How to call stored function in php? Call a stored procedure? What's the trigger?
We have learned so much about PHP, but I don’t know how to call stored functions in PHP? Call a stored procedure? What's the trigger? Have you fully mastered it? If not, then follow this article to continue learning
Related recommendations:What are the usages of is, between, in and other operators in PHP?
Instructions for using stored functions or stored procedures in php
//Calling stored functions:
$v1= $_POST["a];sv2 = $_POST["b]; $sq1 = "insert into tab1 (id, f2, f3)values ( null,nowO. fumnc1(Sv1 , $v2) )":$result= mysql_query($sql);
//Call stored procedure:
$v1 = $_POST[ "usemame"];$v2=$_POST["pass"];sv3= $_POST["age"]; $sql ="callinsert_user(Sv1,$v2,$v3 ); ";llinsert_user)是一个存储过程,带3个参数,会将该3个参数数据写入<insert〉某个表中。 Sresult = mysql_queryO;
Another example of using a stored procedure to return a result set
$sql m"call Get_User_iInfo( sid )“;//Get_User_info)是一个存储过程,其中会返回某个指定id 的用户信息$result = mysql_query(ssql);
What you get here is the "result set "
Trigger (trigger)
Meaning:
Trigger is also a predefined programming code 〈Same as stored procedures and stored functions〉, and has a name. But: it cannot be called, but when an event (add, delete, change) occurs in a certain table, it will be automatically "triggered" and called.
Definition form:
create trigger触发器名︰触发时机触发事件on表名foreach rowasbegin //这里,才是编程的位置,也就是触发器的内部语句end3
Instructions:
1, there are only 2 trigger timings: before《before...), after》 ﹔2. There are only 3 trigger events: insert, update, delete
2. There are only 3 trigger events: insert, update, delete
3, that is, the meaning of the trigger is: Before (or after) insert (or update, or delete) on a certain table, the code (statement) written in it will be executed; that is, there are only 6 situations in each table that may call the trigger,
4. Usually, triggers are used when adding, deleting, or modifying a table and need to do another thing at the same time; 5. Inside the trigger, there are two keywords representing some kind of Specific meaning, you can use to obtain data:
new:
It represents the "new row" data when the insert update is currently being executed; through it , you can get the value of any field of this new row of data, in the form:
set@v1 = new.id;
//Get the value of the id field of the newly inserted or updated row (provided that the id exists)
set@v2 = new.age;//同上,
old:
It represents the "old row" data when the delete is currently being executed. Through it, you can get the value of any field of this old row data in the form:
set @v1 = old.id:I
Get the value of the id field of the newly inserted or updated row (provided that the id exists)
set @v2 = old.age;//同上;
#Delete all the data in tab_int_max first:
delete from tab_int_max1;
#Get tab_int The maximum value of the f1 field in is stored in the variable @maxfselect max(f1) into @maxf1 from tab_int;
#Then, based on the maximum value of the f1 field obtained, as a condition, 3 fields are taken out Value:
select f2 into @v2 from tab_int where f1 = @maxf1; select f3 into @v3 from tab_int _ where f1 = @maxf1;#然后,将@maxf1,@v2,@v3插入到表tab_int_max1 insert into tab_int_max1 (f1,f2,f3)values( @maxf1,@v2,@v3);end; #再建一个触发器,在表tab_int进行insert之前,将该行数据#也同时插入到一个跟其类似结果的表(tab_int_some)中 :CREATE TABLE tab_int_some ( id int(11) DEFAULT NULL,age tinyint(4) DEFAULT NULL); create trigger copy_data before insert on tab_int for each rowbegin set @v1 = new.f1; #获得新行的字段f1的值; set @v2 = new.f2;#获得新行的字段f2的值; insert into tab_int_some(id,age)values(@v1,@v2);end;
Recommended learning: php video tutorial
The above is the detailed content of How to call stored function in php? Call a stored procedure? What's the trigger?. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools