2017-02-20 65 views
0

MySQL存儲過程:傳遞變量到程序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 

如何傳遞變量$操作,$ ora_alocare對存儲在Mysql的程序?谷歌沒有任何好的答案。

回答

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);