Php - Mysql存储过程不返回数据

时间:2021-12-09 16:38:00

I am working in a project that involves Php - Mysql. I have the following stored procedure in MySQL: `

我正在一个涉及Php - Mysql的项目中工作。我在MySQL中有以下存储过程:`

CREATE PROCEDURE alumnos_get_alumno(IN ci INT UNSIGNED)
    READS SQL DATA
BEGIN
   SELECT idalumnos, CONVERT(primer_nombre USING utf8) AS primer_nombre, 
          CONVERT(segundo_nombre USING utf8) AS segundo_nombre, 
          CONVERT(tercer_nombre USING utf8) AS tercer_nombre, 
          CONVERT(primer_apellido USING utf8) AS primer_apellido, 
          CONVERT(segundo_apellido USING utf8) AS segundo_apellido, 
          fecha_nac, estado_actual 
     FROM alumnos WHERE idalumnos = ci;
END`

And I call it from the following Php script:

我从以下Php脚本中调用它:

$config= parse_ini_file("../config/cole.ini");
$connect= mysqli_connect("localhost", $config['username'], $config['password'], $config['dbname']) or die("NO DB Connection");

$getparams = filter_input_array(INPUT_GET);
$query = "CALL alumnos_get_alumno(".$getparams['c'].")";
$result = mysqli_query($connect, $query);
$cuantos = mysqli_num_rows($result);
if ($cuantos != 0){
    while ($row = mysqli_fetch_assoc($result)){
            $output = json_encode($row);
    }
} else {
    $output = 0;
}
echo $output;

Now, the problem is that when executing the Php script, I get an empty response.

现在,问题是当执行Php脚本时,我得到一个空响应。

I tried debugging the script execution with Firebug, and actually seen that the procedure DOES return data (tried with print_r() and got back the array with the data), but when I try to store said data in the $output variable using json_encode(), it "disappears" so to speak.

我尝试用Firebug调试脚本执行,并且实际看到过程DOES返回数据(尝试使用print_r()并使用数据返回数组),但是当我尝试使用json_encode将所述数据存储在$ output变量中时( ),它“消失”可以这么说。

I have several other procedures that are exactly the same thing just changing the table name, and those do work without any problems.

我有几个其他程序只是改变表名完全相同的东西,这些程序没有任何问题。

EDIT: I also checked the log in /var/log/apache2/err.log to see if there were any errors reported by the server, but nothing of the sorts appears.

编辑:我还检查了/var/log/apache2/err.log中的日志,看看服务器是否报告了任何错误,但没有出现任何排序。

What am I missing here?

我在这里想念的是什么?

1 个解决方案

#1


1  

To store response you need to create an array assing your while loop value to that array then use json_encode

要存储响应,您需要创建一个数组,为您的数组提供while循环值,然后使用json_encode

$output = array();
if ($cuantos != 0) {

    while ($row = mysqli_fetch_assoc($result)) {
        $output[] = $row;
    }
} else {
    $output[] = 0;
}

$output = json_encode($output);

#1


1  

To store response you need to create an array assing your while loop value to that array then use json_encode

要存储响应,您需要创建一个数组,为您的数组提供while循环值,然后使用json_encode

$output = array();
if ($cuantos != 0) {

    while ($row = mysqli_fetch_assoc($result)) {
        $output[] = $row;
    }
} else {
    $output[] = 0;
}

$output = json_encode($output);