【发布时间】:2015-05-15 08:23:08
【问题描述】:
我正在尝试在 Cakephp 中创建存储过程。我在 MYSQL 中创建了过程,并在 AppModel.php 中创建了全局函数来命中过程。 AppModel 中的函数是 sProcedure。现在我有 2 个条件,我可能有从过程返回的变量,或者可能有直接的结果集,例如。我为分页创建了。虽然它拍摄了我的程序但没有返回任何结果。我的功能需要修改吗?
public function sProcedure($name = NULL, $inputParameter = array(), $outputParameter = array()) {
$this->begin();
$parameter = "";
$outputParam = "";
foreach ($inputParameter as $params) {
$parameter .= $parameter == "" ? " '$params' " : ", '$params' ";
}
if (count($outputParameter) > 0) {
foreach ($outputParameter as $prm) {
$outputParam .= $outputParam == "" ? " @$prm " : ", @$prm ";
}
}
$parameter = ($outputParam) ? $parameter . ", " . $outputParam : $parameter;
$this->query("CALL `$name`($parameter);");
$result = $this->query("SELECT $outputParam");
$this->commit();
return $result;
}
$sel_data = $this->ArticleNews->sProcedure("update_blank", $input_prameter, $output);
debug($sel_data);
【问题讨论】:
-
您是否遇到任何错误
-
我没有收到错误,我的程序也执行了。但我想知道如何从程序中获取输出。使用相同的功能。无论我是否有输出结果集或变量。
-
@Sankalp 是直接从 MySQL(不使用 PHP)调用时返回合法值的过程吗?此外,$this->query 执行传递的查询字符串并返回(如果没有失败)应该迭代的资源。
-
是的,它返回正确的值。问题是有时我从 SQL 中返回数据集,就像在 Pagnation 中一样。在这种情况下,我是否需要在程序中提及列名或只是
SELECT *。在这种情况下如何阅读响应。在那个场景中,我不会提到输出变量。但是如果我需要特定的列,比如 count 或任何其他函数,我会提到输出变量。两者都可以吗。是否需要适度。
标签: php mysql cakephp stored-procedures