您的位置:首页 > 编程语言 > PHP开发

转贴 MySQL Multiple Result Procs in PHP

2010-05-21 00:34 429 查看
转自:http://www.robert-gonzalez.com/2007/06/01/mysql-multiple-result-procs-in-php/

代码<html>
<head><title>Stored Procedure Tester - MySQL</title></head>

<body>
< ?php
$sql = '';
$show_results = false;

if (isset($_POST['form_submitted']))
{
// The form was submitted
$sql = $_POST['query'];

echo '<p>The query you entered entered was <strong>' . $sql . '</strong>.';

// Change the params to you own here...
$mysql = new mysqli('localhost', 'USER', 'PASSWORD', 'DATABASENAME');

if (mysqli_connect_errno())
{
die(printf('MySQL Server connection failed: %s', mysqli_connect_error()));
}

// Check our query results
if ($mysql->multi_query($sql))
{
$show_results = true;
$rs = array();

do {
// Lets work with the first result set
if ($result = $mysql->use_result())
{
// Loop the first result set, reading it into an array
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
$rs[] = $row;
}

// Close the result set
$result->close();
}
} while ($mysql->next_result());
}
else
{
echo '<p>There were problems with your query [' . $sql . ']:<br /><strong>Error Code ' . $mysql->errno . ' :: Error Message ' . $mysql->error . '</strong></p>';
}

$mysql->close();
}

echo '<form id="proc_tester" action="' . basename($_SERVER['SCRIPT_FILENAME']) . '" method="post">
<p>Enter your procedure:</p>
<p><input type="text" name="query" size="175" maxlength="255" value="' . $sql . '" /></p>
<p><input type="hidden" name="form_submitted" value="true" /><input type="submit" name="submit" value="Submit query" /></p>
</form>';

if ($show_results) {
echo '<pre>';
print_r($rs);
echo '< /pre>';
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐