Skip to content

Instantly share code, notes, and snippets.

@pipiscrew
Created May 1, 2014 14:01
Show Gist options
  • Save pipiscrew/11452256 to your computer and use it in GitHub Desktop.
Save pipiscrew/11452256 to your computer and use it in GitHub Desktop.
[php+mysql] read OUT parameter from procedure
//procedure
DELIMITER $$
CREATE PROCEDURE ADD_CAUSECOMPANY (IN fb_idVAR varchar(50), OUT resVAL INT)
BEGIN
DECLARE x INT;
select id into x from fb_causescompanies where fb_id = fb_idVAR;
IF (x > 0 ) THEN
//update statement
set resVAL := 1;
ELSE
//insert statement
set resVAL := 2;
END IF;
END$$
DELIMITER ;
//PHP
<?php
if ($stmt = $mysqli -> prepare("call ADD_CAUSECOMPANY (?, @ouput)")) {
//bind parameter
$stmt -> bind_param('s', $fb_id);
$fb_id = 'test';
//Execute the prepared Statement
$stmt -> execute();
//qway 1
$res = mysqli_query($mysqli, "select @ouput");
$t = mysqli_fetch_array($res,MYSQLI_ASSOC);
echo($t["@ouput"]);
//way 2
$res = mysqli_query($mysqli, "select @ouput");
while($r = mysqli_fetch_array($res,MYSQLI_ASSOC)) {
echo($r);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment