我在MySQL上有一个存储过程,例如:
CREATE PROCEDURE get_multiple_results()
BEGIN
SELECT 'A' AS A;
SELECT 'B' AS B;
SELECT 'C' AS C;
END
那么,如何使用CodeIgniter的查询方式获取数据呢?
$this->db->query('CALL get_multiple_results()')->result_array();
谢谢!
最佳答案
只需调用下面编写的方法并获取查询结果的数组(列表),例如 $resultSet = $this->GetMultipleQuery("CALL my_proc ('$input')");
查询字符串也可以是多个选择查询的串联。
/**
* To get result(s) of queries that returns multiple result sets...
*
* @author Pankaj Garg <garg.pankaj15@gmail.com>
*
* @param string $queryString
*
* @return bool|array List of result arrays
*/
public function GetMultipleQueryResult($queryString)
{
if (empty($queryString)) {
return false;
}
$index = 0;
$ResultSet = array();
/* execute multi query */
if (mysqli_multi_query($this->db->conn_id, $queryString)) {
do {
if (false != $result = mysqli_store_result($this->db->conn_id)) {
$rowID = 0;
while ($row = $result->fetch_assoc()) {
$ResultSet[$index][$rowID] = $row;
$rowID++;
}
}
$index++;
} while (mysqli_next_result($this->db->conn_id));
}
return $ResultSet;
}
关于php - CodeIgniter 存储过程的多个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18000704/