久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP:使用 INPUT 和 OUTPUT 參數(shù)(非“INOUT")調(diào)用 M

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT quot;INOUTquot;)(PHP:使用 INPUT 和 OUTPUT 參數(shù)(非“INOUT)調(diào)用 MySQL 存儲過程)
本文介紹了PHP:使用 INPUT 和 OUTPUT 參數(shù)(非“INOUT")調(diào)用 MySQL 存儲過程的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想從 PHP 調(diào)用 MySQL 中的存儲過程.該過程采用輸入輸出參數(shù)——不是INOUT"參數(shù).

From PHP I would like to call a stored procedure in MySQL. The procedure takes input and output parameters -- not "INOUT" parameters.

舉個(gè)簡單的例子,假設(shè)我在 MySQL 中有以下存儲過程:

For a simple example, say I have the following stored procedure in MySQL:

DELIMITER $$

DROP PROCEDURE IF EXISTS `test_proc`$$
CREATE PROCEDURE `test_proc`(
    in input_param_1 int,
    in input_param_2 int,
    in input_param_3 int,
    out output_sum int,
    out output_product int,
    out output_average int
)
BEGIN
    set output_sum = input_param_1 + input_param_2 + input_param_3;
    set output_product = input_param_1 * input_param_2 * input_param_3;
    set output_average = (input_param_1 + input_param_2 + input_param_3) / 3;
END$$

DELIMITER ;

現(xiàn)在,從 PHP 腳本/頁面方面,假設(shè)我有以下變量(我們將它們稱為proc 輸入變量"),我想將它們作為 輸入 參數(shù)提供給存儲過程當(dāng)我調(diào)用它時(shí):

Now, from the PHP script/page side, say I have the following variables (we'll call them "proc input variables") that I want to feed to the stored procedure as input parameters when I call it:

$procInput1 = "123";
$procInput2 = "456";
$procInput3 = "789";

假設(shè)在 PHP 腳本/頁面方面,我還有以下變量(我們將它們稱為proc 輸出變量"),我想將它們作為 輸出 參數(shù)提供給存儲過程在我調(diào)用它時(shí)由存儲過程設(shè)置:

Let's say that on the PHP script/page side I also have the following variables (we'll call them "proc output variables") that I want to feed to the stored procedure as output parameters to be set by the stored procedure when I call it:

$procOutput_sum;
$procOutput_product;
$procOutput_average;

所以,本質(zhì)上,在 PHP 腳本/頁面方面,我想要做的本質(zhì)上是(我意識到以下代碼無效),是...

So, in essence, on the PHP script/page side, what I want to be able to do, in essence (I realize the following code is not valid), is...

call test_proc($procInput1, $procInput2, $procInput3, $procOutput_sum, $procOutput_product, $procOutput_average);

...并且,一旦調(diào)用,以下 PHP 代碼...

...and, once called, the following PHP code...

echo "Sum: ".$procOutput_sum;
echo "Product: ".$procOutput_product;
echo "Average: ".$procOutput_average;

...應(yīng)該產(chǎn)生以下輸出:

...should produce the following output:

Sum: 1368
Product: 44253432
Average: 456

一個(gè)警告是,如果可能的話,我希望能夠使用 MySQLi 過程 函數(shù)/接口來做到這一點(diǎn).如果不可能,那么我可以使用它.

One caveat is that, if at all possible, I would like to be able to do this using the MySQLi procedural functions/interface. If not possible, then however I can get it to work is what I'll use.

我已經(jīng)有一段時(shí)間編程了,但 PHP 語言對我來說是一個(gè)相對較新的嘗試.我找到了大量關(guān)于從 PHP 調(diào)用 MySQL 存儲過程的教程.有些是使用輸入參數(shù)調(diào)用存儲過程的教程,有些是使用輸出參數(shù)調(diào)用存儲過程的教程,還有一些是使用inout<調(diào)用存儲過程的教程/strong> 參數(shù).我還沒有找到任何關(guān)于調(diào)用存儲過程的教程或示例,這些存儲過程同時(shí)輸入輸出參數(shù),而特別使用"inout"參數(shù).我無法弄清楚如何對參數(shù)綁定(例如:mysqli_stmt_bind_param 和 mysqli_stmt_bind_result)進(jìn)行編碼并使其全部正常工作.

I have been programming for quite some time, but the PHP language is a relatively new endeavor for me. I have found tons of tutorials on calling MySQL stored procedures from PHP. Some are tutorials on calling stored procedures with input parameters, some are tutorials on calling stored procedures with output parameters, and some are tutorials on calling stored procedures with inout parameters. I have not found any tutorials or examples on calling stored procedures that take both input and output parameters at the same time, while specifically not using "inout" parameters. I'm having trouble figuring out how to code the parameter bindings (e.g.: mysqli_stmt_bind_param and mysqli_stmt_bind_result) and getting it all to work properly.

任何幫助將不勝感激,我提前表示感謝!

Any help will be greatly appreciated and I give thanks in advance!

推薦答案

不幸的是,MySQLi 沒有 對輸出 sproc 參數(shù)有任何本機(jī)支持;必須改為輸出到 MySQL 用戶變量,然后使用單獨(dú)的 SELECT 獲取值 語句.

Unfortunately, MySQLi does not have any native support for output sproc parameters; one must instead output into MySQL user variables and then fetch the values using a separate SELECT statement.

使用程序界面:

$procInput1 = 123;
$procInput2 = 456;
$procInput3 = 789;

$mysqli = mysqli_connect();

$call = mysqli_prepare($mysqli, 'CALL test_proc(?, ?, ?, @sum, @product, @average)');
mysqli_stmt_bind_param($call, 'iii', $procInput1, $procInput2, $procInput3);
mysqli_stmt_execute($call);

$select = mysqli_query($mysqli, 'SELECT @sum, @product, @average');
$result = mysqli_fetch_assoc($select);
$procOutput_sum     = $result['@sum'];
$procOutput_product = $result['@product'];
$procOutput_average = $result['@average'];

或者,使用面向?qū)ο蟮慕涌?

Or, using the object-oriented interface:

$procInput1 = 123;
$procInput2 = 456;
$procInput3 = 789;

$mysqli = new mysqli();

$call = $mysqli->prepare('CALL test_proc(?, ?, ?, @sum, @product, @average)');
$call->bind_param('iii', $procInput1, $procInput2, $procInput3);
$call->execute();

$select = $mysqli->query('SELECT @sum, @product, @average');
$result = $select->fetch_assoc();
$procOutput_sum     = $result['@sum'];
$procOutput_product = $result['@product'];
$procOutput_average = $result['@average'];

這篇關(guān)于PHP:使用 INPUT 和 OUTPUT 參數(shù)(非“INOUT")調(diào)用 MySQL 存儲過程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久久久欧美 | 一区免费| 精品久久久久久18免费网站 | 久久99精品久久久久蜜桃tv | 亚洲狠狠丁香婷婷综合久久久 | 日韩视频在线免费观看 | 久久男人| 国产一区免费视频 | 日韩久久综合 | 成人免费一区二区三区视频网站 | 日本淫视频 | 久久久久久久国产精品视频 | 一级毛片播放 | 国产精品视频免费观看 | www.成人久久 | 日日摸夜夜爽人人添av | 日韩毛片在线观看 | 日本一卡精品视频免费 | 国产在线视频99 | 99久久亚洲| 成人午夜电影在线观看 | 欧美无乱码久久久免费午夜一区 | 欧美成人一区二免费视频软件 | 欧美福利视频 | 欧美久久一区 | 91精品久久久久久久久中文字幕 | 亚洲精品自拍视频 | 午夜影院视频 | 欧美一级黄色片在线观看 | 精品视频一区二区三区 | 亚洲一区亚洲二区 | 色综合一区二区三区 | 精品一区在线免费观看 | 精品久久久久久亚洲精品 | 亚洲视频在线一区 | 国产一级在线观看 | 美女黄视频网站 | 嫩呦国产一区二区三区av | 综合国产在线 | 日韩国产在线观看 | 男人av在线播放 |