db->query(-6ren">
gpt4 book ai didi

php - 尝试使用 CodeIgniter 存储过程 'call'

转载 作者:可可西里 更新时间:2023-11-01 07:50:05 24 4
gpt4 key购买 nike

我有 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');

我得到错误:

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

到底出了什么问题?

谢谢

最佳答案

以防万一它能帮助到任何人。我使用这个库在 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;

}
}
?>

从 Controller 中这样调用它

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

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

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

关于php - 尝试使用 CodeIgniter 存储过程 'call',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9046075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com