PHP_PDO 調用預存程序,返回參數有關問題

來源:互聯網
上載者:User
PHP_PDO 調用預存程序,返回參數問題
$stmt = $db->prepare("CALL pro_test(?,@?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $return_value, PDO::PARAM_STR, 4000);


// 插入一行
$name = '成都市';
$stmt->execute ();

print_r($return_value);


調用預存程序,返回參數怎麼是空的,麼有,查看資料庫,已經成功添加了資料,
直接在資料庫中執行
SET @n = -1;
CALL pro_test("啊是打算",@n);
select @n;
返回的都是正確的參數

分享到: 更多


------解決方案--------------------
調用預存程序時,資料庫可能返回多個結果集
依次是:基本的 select 的結果,預存程序1的結果,預存程序2的結果 ....
你的 SQL 指令這是 CALL pro_test(?,@?) 沒有 select 所以只能位於第二個結果集
如果寫作 select CALL pro_test(?,@?) 就位於第一結果集了
當然環境十多變的,你也確實不能準確的知道結果集會擺在哪裡
於是就需要迴圈讀取
  do {
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
if ($rows) {
print_r($rows);
}
} while ($stmt->nextRowset());
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.