Mysql存储过程:
BEGIN
INSERT INTO `flux_zilnic` (motiv,nume_client,data_inregistrare,ora_inregistrare,status_alocare,ora_alocare,status_preluare,ora_preluare,status_rezolvare,ora_rezolvare,operator,birou,fisa_service)
SELECT '',nume_client,data_inregistrare,ora_inregistrare,'ALOCAT','$ora_alocare','','','','','$operator','BIROUL 2',''
FROM `tableta` ORDER BY id ASC LIMIT 1;
UPDATE `birouri` SET `disponibilitate` = 'OCUPAT' WHERE `birouri`.`username` = '$operator';
DELETE FROM `tableta` ORDER BY id ASC LIMIT 1;
END
PHP脚本调用过程:
//CODE HERE
$operator = "user_name";
$current_date = date_create('');
$ora_alocare = date_format($current_date, 'H:i');
//CODE HERE
$result = mysqli_query($connection, "CALL allocateClients()");
//CODE HERE
如何将变量$ operator,$ ora_alocare传递给Mysql存储过程?我无法在谷歌找到任何好的答案。
答案 0 :(得分:0)
尝试这样:
DELIMITER $$
DROP PROCEDURE IF EXISTS `procedureExample` $$
CREATE PROCEDURE `procedureExample`(IN ora_alocare_param TIME,in operator_param varchar(20))
BEGIN
INSERT INTO `flux_zilnic` (motiv,nume_client,data_inregistrare,ora_inregistrare,status_alocare,ora_alocare,status_preluare,ora_preluare,status_rezolvare,ora_rezolvare,operator,birou,fisa_service)
SELECT '',nume_client,data_inregistrare,ora_inregistrare,'ALOCAT',ora_alocare_param,'','','','',operator_param,'BIROUL 2',''
FROM `tableta` ORDER BY id ASC LIMIT 1;
UPDATE `birouri` SET `disponibilitate` = 'OCUPAT' WHERE `birouri`.`username` = operator_param;
DELETE FROM `tableta` ORDER BY id ASC LIMIT 1;
END $$
DELIMITER ;
<强> PHP 强>
$call = mysqli_prepare($connection, 'CALL procedureExample(?, ?)');
mysqli_stmt_bind_param($call, 'ss',$ora_alocare, $operator);
mysqli_stmt_execute($call);