My procedures mysql already does inserts correctly:
this is my php code calling the procedure:
$sql = 'CALL insert_menu(?,?,?,?,?)';
try {
$query = $bd->prepare($sql);
$query->bindParam(1,$name, PDO::PARAM_STR);
$query->bindParam(2,$catsup, PDO::PARAM_INT);
$query->bindParam(3,$level, PDO::PARAM_INT);
$query->bindParam(4,$link, PDO::PARAM_STR);
$query->bindParam(5,$title, PDO::PARAM_STR);
$query->execute();
} catch (PDOException $e) {
echo $e->getMessage();
}
and this is my procedure:
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_menu`(
IN p_cat_name VARCHAR(100),
IN p_cat_sup_cod INT,
IN p_cat_level INT,
IN p_link VARCHAR(200),
IN p_title VARCHAR(100)
)
BEGIN
IF ((p_cat_name <> '')&&(p_cat_level <> '')&&(p_link <> '')&&(p_title <> '')) THEN
INSERT INTO access (access_id,menu_descr,sup_cod,level,menu_link,menu_title)
VALUES ('',p_cat_name,p_cat_sup_cod,p_cat_level,p_link,p_title);
END IF;
END;
I would like that my procedure returns to the php the last inserted id…
I also do not know how to get the result with PDO prepare…
I ask everyone’s help, thank you …
Since you’re using PDO:
But this really doesn’t need a prepare, so you could just use: