我很难将数据从MySQL过程返回到PHP脚本。特别是我在php中有一系列选项菜单,用户可以从中选择。其中两个菜单是可选的,根据它们选择或不选择哪个选项,选择I执行不同的选择查询。
下面是我从MySQL工作台调用它时正常工作的存储过程(字段名称已更改)但是当我使用
从PHP调用它时不会返回任何结果$searchResult=mysql_query("call search(50,'Find_All_OF_Field1','Find_All_OF_Field2')");
或其任何组合。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `search`(isize int, optional_Field1 varchar(500), optional_Field2 varchar(500))
BEGIN
if optional_Field1 like 'Find_All_OF_Field1' and optional_Field2 LIKE 'Find_All_OF_Field2' THEN
SELECT product_name, price
FROM products
WHERE size =isize;
ELSEIF optional_Field1 LIKE 'Find_All_OF_Field1' THEN
SELECT product_name, price
FROM products
WHERE size =isize And manufacturer=optional_Field2;
ELSEIF optional_Field2 LIKE 'Find_All_OF_Field2' THEN
SELECT product_name, price
FROM products
WHERE size =isize And style=optional_Field1;
ELSE
SELECT product_name, price
FROM products
WHERE size =isize And style=optional_Field1 AND manufacturer=optional_Field2;
end if;
END