我想从php中的mysql存储过程中获取结果集。我怎样才能做到这一点?任何帮助表示赞赏。最好是有人可以发布代码片段! 例如,如果我有一个登录表。我创建了一个存储过程
SELECT * FROM login
现在我需要在php中调用这个存储过程并迭代结果集
答案 0 :(得分:0)
PHP:
$mysqli = new mysqli("localhost", "root", "", "quadv2_dev");
if (!$mysqli->multi_query("CALL testlist()")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
do {
if ($res = $mysqli->store_result()) {
printf("---\n<pre/>");
print_r($res->fetch_all());
$res->free();
} else {
if ($mysqli->errno) {
echo "Store failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
}
} while ($mysqli->more_results() && $mysqli->next_result());
mysql:
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `quadv2_dev`.`testlist`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
SET @Qry ="SELECT * FROM Content";
PREPARE st FROM @Qry;
EXECUTE st;
DEALLOCATE PREPARE st;
END$$
DELIMITER ;