由于下面的代码PersonID
在一个表中是主键而在另一个表中是外键,我已经在php中编写了这段代码
$query = mysqli_query($conn,"UPDATE employee SET Firstname = '$fname', Lastname ='$lname', email_id ='$email', Mobile_no ='$mobile', city='$city' WHERE PersonID = '$userid'");
$query = mysqli_query($conn,"UPDATE experience SET Company_name = '$com', Location ='$local', Year_Of_Experience ='$year', Description ='$description' WHERE PersonID = '$userid'");
现在我想在sp中编写上面的代码,任何人都知道怎么写?
答案 0 :(得分:0)
在PHPMyAdmin中运行以下内容并使用它
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE DATABASE_NAME.`update_sp`(IN PersonID DATATYPE(size),IN Firstname DATATYPE(size), IN Lastname DATATYPE(size), IN email_id DATATYPE(size), IN Mobile_no DATATYPE(size), IN city DATATYPE(size),
IN Location DATATYPE(size), IN Year_Of_Experience DATATYPE(size), IN Description DATATYPE(size))
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
UPDATE employee SET Firstname = REPLACE(Firstname,"'","`"), Lastname =REPLACE(Lastname,"'","`"), email_id =REPLACE(email_id,"'","`"),
Mobile_no =REPLACE(Mobile_no,"'","`"), city=REPLACE(city,"'","`") WHERE PersonID = REPLACE(PersonID,"'","`");
UPDATE experience SET Company_name = REPLACE(Company_name,"'","`") , Location =REPLACE(Location,"'","`") , Year_Of_Experience =REPLACE(Year_Of_Experience,"'","`") ,
Description =REPLACE(Description,"'","`") WHERE PersonID = REPLACE(PersonID,"'","`") ;
END$$
DELIMITER ;
您可以通过传递参数来调用它,就像调用函数一样。