转贴 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>';
}
?>
代码<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>';
}
?>
相关文章推荐
- 2015-03-19 create php alternative for myslq_result in mysqli(PHP)--PDO Tutorial for Mysql Developers
- PHP调用存储过程失败(没有执行到)--mysql_error()--can't return a result set in the given context
- Fatal Error: ezSQL_mysql requires mySQL Lib to be compiled and or linked in to the PHP engine
- 转贴 Using MySQL Stored Procedures with PHP mysql/mysqli/pdo
- 关于warning: mysql_result() expects parameter 1 to be resource,object given in……的解决方法
- How To Use MySQL Easily In PHP
- php中的释放语句unset和释放函数mysql_free_result()
- mysql_fetch_field(): supplied argument is not a valid MySQL result resource in
- 处理PHP mysql_query执行超时 【Fatal error: Maximum execution time of 300 seconds exceeded in……】
- How to Create a Secure Login Script in PHP and MySQL
- How to install LAMP (Apache, PHP and MySQL in Linux) using Yum
- 安装 Fatal error: Maximum execution time of 30 seconds exceeded in …/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php on line 230
- 报错提示:mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in..的处理方式
- log:linux deepin下配置apache+php+mysql
- How to get multiple select value both in javascript and php
- Fatal error: Call to undefined function mysql_connect() in (php链接mysql时出现的错误)
- Fatal error: Call to undefined function mysql_connect() in D:\phpwww\index.php
- php在iis上配置时报Fatal error: Call to undefined function mysql_connect() in 错误解决办法
- PHP mysql_result() 函数
- [转贴]vista 配置apache + mysql + php