dongzhuo7291 2012-09-30 04:28 采纳率: 100%
浏览 180
已采纳

在php中使用'out'参数调用mysql函数或存储过程

I have used mysql stored procedure in php, but i need to return few values from my sql, so i am planning to use mysql functions or stored procedure with ''out'parameter.

it would be good if anyone can help me on that.

  • 写回答

2条回答 默认 最新

  • doushi8599 2012-10-03 04:19
    关注

    i found solution for this

    http://blog.ulf-wendel.de/2011/using-mysql-stored-procedures-with-php-mysqli/

      $mysqli = new mysqli("localhost", "root", "", "test");
    if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
        !$mysqli->query('CREATE PROCEDURE p(OUT msg VARCHAR(50)) BEGIN SELECT "Hi!" INTO msg; END;'))
       echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
    
    if (!$mysqli->query("SET @msg = ''") ||
        !$mysqli->query("CALL p(@msg)"))
     echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
    
    if (!($res = $mysqli->query("SELECT @msg as _p_out")))
     echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
    
    $row = $res->fetch_assoc();
    echo $row['_p_out'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探