这是我在mysql中的商店程序。当我在phpmyadmin中调用它时,确定并完成了
打电话给phpmyadmin
CALL sp_del_temp_record(' tbl_user_login_and',1880,10)
但是当我在mysql_query中使用它时它不起作用:
mysql_query(" CALL sp_del_temp_record(' tbl_user_login_and',1877,10)");
这是我的sp:
CREATE PROCEDURE `sp_del_temp_record`(p_tbl varchar(255), max_record smallint(6),del_count smallint(6))
BEGIN
SET @count_query=CONCAT ("select count(auto_id) into @count_record from ",p_tbl);
PREPARE count_record_q FROM @count_query;
EXECUTE count_record_q;
if @count_record>max_record then
SET @del_query=CONCAT ("delete from ",p_tbl," order by auto_id asc limit ",del_count);
PREPARE del_query_q FROM @del_query;
EXECUTE del_query_q;
end if;
END;
答案 0 :(得分:1)
尝试这种方式:
DELIMITER $$
CREATE PROCEDURE `sp_del_temp_record`(p_tbl varchar(255), max_record smallint(6),del_count smallint(6))
BEGIN
SET count_query=CONCAT ("select count(auto_id) into count_record from ",p_tbl);
PREPARE count_record_q FROM count_query;
EXECUTE count_record_q;
if count_record>max_record then
SET del_query=CONCAT ("delete from ",p_tbl," order by auto_id asc limit ",del_count);
PREPARE del_query_q FROM del_query;
EXECUTE del_query_q;
end if;
END$$
DELIMITER ;
答案 1 :(得分:0)
$thisGuy = new MySQLI(inputParamsHere);
$retVal = $thisGuy->multi_query("CALL myDB.storedProc($var1, $var2, @return1, @return2);
select @return1 as firstValue, @return2 as secondValue;");
if ($retVal) getResultSets();
尝试使用mysqli multi_query
public function getResultSets() {
$retVal = array();
do {
if ($result = $this->mysqli->store_result())
$retVal[] = $result;
} while ($this->mysqli->next_result());
return $retVal;
}