56,677
社区成员
发帖
与我相关
我的任务
分享
$sql="create procedure p(out nums INT)
Begin
select count(*) into nums from a;
End;";
$result = $db->query("call p(@nums)");
$result = $db->query("select @nums as nums");
while($row=$result->fetch_assoc())
{
$Rows[] = $row;
}
print($Rows);
Array
(
[0] => Array
(
[nums] =>
)
)
The values of INOUT/OUT parameters are accessed using session variables.
Example 3.20 Using session variables
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
!$mysqli->query('CREATE PROCEDURE p(OUT msg VARCHAR(50)) BEGIN SELECT "Hi!" INTO msg; END;')) {
echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$mysqli->query("SET @msg = ''") || !$mysqli->query("CALL p(@msg)")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!($res = $mysqli->query("SELECT @msg as _p_out"))) {
echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$row = $res->fetch_assoc();
echo $row['_p_out'];
?>
你看这个例程 写的很清楚 输出参数是存储在会话变量里的 所以你得先 定义会话变量
我估计这就是你失败的原因The values of INOUT/OUT parameters are accessed using session variables.
Example 3.20 Using session variables
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
!$mysqli->query('CREATE PROCEDURE p(OUT msg VARCHAR(50)) BEGIN SELECT "Hi!" INTO msg; END;')) {
echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$mysqli->query("SET @msg = ''") || !$mysqli->query("CALL p(@msg)")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!($res = $mysqli->query("SELECT @msg as _p_out"))) {
echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$row = $res->fetch_assoc();
echo $row['_p_out'];
?>
你看这个例程 写的很清楚 输出参数是存储在会话变量里的 所以你得先 定义会话变量
我估计这就是你失败的原因[/quote]
我所有的变量都有定义。The values of INOUT/OUT parameters are accessed using session variables.
Example 3.20 Using session variables
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
!$mysqli->query('CREATE PROCEDURE p(OUT msg VARCHAR(50)) BEGIN SELECT "Hi!" INTO msg; END;')) {
echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$mysqli->query("SET @msg = ''") || !$mysqli->query("CALL p(@msg)")) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!($res = $mysqli->query("SELECT @msg as _p_out"))) {
echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$row = $res->fetch_assoc();
echo $row['_p_out'];
?>
你看这个例程 写的很清楚 输出参数是存储在会话变量里的 所以你得先 定义会话变量
我估计这就是你失败的原因[/quote]
我所有的变量都有定义。[/quote]
你没有理解,是在调用存储过程前需要先定义会话变量
对应的例程中:$mysqli->query("SET @msg = ''");
不是你php的变量 也不是你存储过程里的变量