PHP - 如何将准备好的语句记录为参数
PHP - How to document a prepared statement as parameter
我有这样的代码片段:
$pstmt = $connection->prepare($sql);
foo($pstmt);
现在我想记录 "foo" 方法,需要准备好的语句。
但我只找到\mysqli_stmt
class.
开始编辑
一个"more complete"例子
$connection = pwm\MySQLHelper::getConnection();
$pstmt = $connection->prepare($sql);
$pstmt->bind_param("s", $fbToken);
toJSON($pstmt);
$pstmt->close();
$connection->close();
现在 toJSON($psm)
函数(即上面的 foo($ps)
/**
* @param $data \mysqli_stmt A prepated statement
*/
function toJSON($pstmt)
{
$pstmt->execute();
$result = $pstmt->get_result();
$rarray = [];
while ($row = $result->fetch_assoc()) {
$rarray[] = $row;
}
$result->close();
echo json_encode($rarray);
}
问题是关于 PHPDoc 的。我无法找到与 "mysqli_stmt" 不同的 class,但是使用此代码 PHPStorm 无法识别 "execute()"、"get_result()"、"fetch_assoc()" 和 "close()" .
我想教 PHPStorm,这是一个准备好的语句。
希望编辑有所帮助。
结束编辑
我正在使用 PHPstorm,但 \mysqli_stmt
它无法找到 `execute()' 等。
tl;博士;
如何将准备好的语句记录为参数,因为 \mysqli_stmt
对于 PHPStorm 来说还不够。
变量名和函数参数名不匹配。在 PHPDoc 中你有 $data
在函数中你有 $pstmt
。将 PHPDoc 从 $data
更改为 $pstmt
。之后它应该按预期工作。
我有这样的代码片段:
$pstmt = $connection->prepare($sql);
foo($pstmt);
现在我想记录 "foo" 方法,需要准备好的语句。
但我只找到\mysqli_stmt
class.
开始编辑
一个"more complete"例子
$connection = pwm\MySQLHelper::getConnection();
$pstmt = $connection->prepare($sql);
$pstmt->bind_param("s", $fbToken);
toJSON($pstmt);
$pstmt->close();
$connection->close();
现在 toJSON($psm)
函数(即上面的 foo($ps)
/**
* @param $data \mysqli_stmt A prepated statement
*/
function toJSON($pstmt)
{
$pstmt->execute();
$result = $pstmt->get_result();
$rarray = [];
while ($row = $result->fetch_assoc()) {
$rarray[] = $row;
}
$result->close();
echo json_encode($rarray);
}
问题是关于 PHPDoc 的。我无法找到与 "mysqli_stmt" 不同的 class,但是使用此代码 PHPStorm 无法识别 "execute()"、"get_result()"、"fetch_assoc()" 和 "close()" . 我想教 PHPStorm,这是一个准备好的语句。
希望编辑有所帮助。
结束编辑
我正在使用 PHPstorm,但 \mysqli_stmt
它无法找到 `execute()' 等。
tl;博士;
如何将准备好的语句记录为参数,因为 \mysqli_stmt
对于 PHPStorm 来说还不够。
变量名和函数参数名不匹配。在 PHPDoc 中你有 $data
在函数中你有 $pstmt
。将 PHPDoc 从 $data
更改为 $pstmt
。之后它应该按预期工作。