21,893
社区成员




<?php
$conn = new PDO('mysql:host=localhost;dbname=test', 'root', '123456');
$sql = 'CALL sp_test()';
$stmt = $conn->query($sql);
$i = 1;
do {
$rowset = $stmt->fetchAll(PDO::FETCH_NUM);
if ($rowset) {
printResultSet($rowset, $i);
}
$i++;
} while ($stmt->nextRowset());
[color=sienna][color=navy]function printResultSet(&$rowset, $i) {
print "Result set $i:\n";
foreach ($rowset as $row) {
foreach ($row as $col) {
print $col . "\t";
}
print "\n";
}
print "\n";
}
?>
$mysqli = new mysqli("localhost", "root", "root", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "call sp_test();";
$mysqli->multi_query($query);
$i = 1;
while($mysqli->more_results()){
if ($result = $mysqli->store_result()) {
while ($rowset = $result->fetch_row()) {
//printf("%s\n", $row[0]);
printResultSet($rowset, $i);
}
$result->close();
}
$i++;
$mysqli->next_result();
}
function printResultSet(&$rowset, $i) {
print "Result set $i:\n";
foreach ($rowset as $row) {
print $row . "\t";
}
print "\n";
}