试图“打电话”;使用 CodeIgniter 存储过程

发布于 2024-12-29 15:31:25 字数 420 浏览 0 评论 0原文

我有 CI 的工作代码:

$this->db->query("call nameOfProcedure('param1', @param2)");
$query = $this->db->query('SELECT @param2 as results');
$row = $query->row();

它可以工作,但如果我尝试使用:

$this->db->call_function('nameOfProcedure', 'param1', '@param2');

我收到错误:

此功能不适用于您正在使用的数据库。

究竟出了什么问题?

谢谢

i've this working code with CI:

$this->db->query("call nameOfProcedure('param1', @param2)");
$query = $this->db->query('SELECT @param2 as results');
$row = $query->row();

it works, but if I try to use:

$this->db->call_function('nameOfProcedure', 'param1', '@param2');

i get the error:

This feature is not available for the database you are using.

What's wrong exactly?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空袭的梦i 2025-01-05 15:31:25

以防万一它对任何人有帮助。我使用这个库来处理 CI 中的存储过程,它也支持多个结果集。

代码

这是我称之为 Mydb.php

<?php #if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mydb
{
   private $CI, $Data, $mysqli, $ResultSet;

   /**
   * The constructor
   */

   function __construct()
   {
     $this->CI =& get_instance();
     $this->Data = '';
     $this->ResultSet = array();
     $this->mysqli = $this->CI->db->conn_id;
   }

    public function GetMultiResults($SqlCommand)
    {
    /* execute multi query */
    if (mysqli_multi_query($this->mysqli, $SqlCommand)) {
        $i=0;
        do
        {

             if ($result = $this->mysqli->store_result()) 
             {
                while ($row = $result->fetch_assoc())
                {
                    $this->Data[$i][] = $row;
                }
                mysqli_free_result($result);
             }
            $i++; 
        }
        while ($this->mysqli->next_result());
    }
    return $this->Data;

   }   
}
?>  

,从控制器中这样调用它

$this->load->library('mydb');
$arr  = $this->mydb->GetMultiResults("CALL GetReferrals()");

另外,请确保设置 mysqli 驱动程序
application/config/database.php

$db['default']['dbdriver'] = 'mysqli';

Just in case it helps anyone. I use this library to work with stored procedures in CI, it supports multiple result sets too.

here is the code

I call it Mydb.php

<?php #if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mydb
{
   private $CI, $Data, $mysqli, $ResultSet;

   /**
   * The constructor
   */

   function __construct()
   {
     $this->CI =& get_instance();
     $this->Data = '';
     $this->ResultSet = array();
     $this->mysqli = $this->CI->db->conn_id;
   }

    public function GetMultiResults($SqlCommand)
    {
    /* execute multi query */
    if (mysqli_multi_query($this->mysqli, $SqlCommand)) {
        $i=0;
        do
        {

             if ($result = $this->mysqli->store_result()) 
             {
                while ($row = $result->fetch_assoc())
                {
                    $this->Data[$i][] = $row;
                }
                mysqli_free_result($result);
             }
            $i++; 
        }
        while ($this->mysqli->next_result());
    }
    return $this->Data;

   }   
}
?>  

call it like this from controller

$this->load->library('mydb');
$arr  = $this->mydb->GetMultiResults("CALL GetReferrals()");

Also, make sure to set mysqli the driver
in application/config/database.php

$db['default']['dbdriver'] = 'mysqli';
疯了 2025-01-05 15:31:25

查看有关 call_function文档。它用于调用非 CI 数据库驱动程序本身的函数,而不是用于调用您编写的过程。

您可以检查 CI 2.1.0 上 /system/database/DB_driver.php Ln 998 中的 call_function 代码,清楚地看到它在做什么。

Check out the docs on call_function. It's for calling functions that aren't native to CI's DB driver, not for calling procedures you've written.

You can check the call_function code in /system/database/DB_driver.php Ln 998 on CI 2.1.0 to see clearly what it's doing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文