mysqli_stmt_bind_resultSQLSRV 的等值线是什么?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (19)

我正在处理注册/登录表单,这是我第一次使用SQLSRV(由于Azure数据库),我似乎无法找到mysqli_stmt_bind_resultSQLSRV 的等值线,有人可以帮我解决这个问题吗?

提问于
用户回答回答于

简单的示例:

<?php
$server = 'server\instance,port';
$cinfo = array(
    "Database"=>'master',
    "UID"=>'user',
    "PWD"=>'password'
);

$conn = sqlsrv_connect($server, $cinfo);
if( $conn === false )
{
    echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
    exit;
}

$sql = 
    "SELECT 'SUSER_SNAME' AS [NAME], CONVERT(varchar(128), SUSER_SNAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'SUSER_NAME' AS [NAME], CONVERT(varchar(128), SUSER_NAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'USER_NAME' AS [NAME], CONVERT(varchar(128), USER_NAME()) AS [VALUE]".
    "UNION ALL ".
    "SELECT 'USER_ID' AS [NAME], CONVERT(varchar(128), USER_ID()) AS [VALUE]";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false ) {
    echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
    exit;
}

while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    echo $row['NAME'].": ".$row['VALUE']."</br>";
}

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>

使用参数的示例:

...
$sql = "SELECT * FROM Gebruikers WHERE username = (?) AND password = (?)";
// $params definition:
// - A literal value.
// - A PHP variable.
// - An array with the following structure:
// array($value [, $direction [, $phpType [, $sqlType]]]) where $direction is one of the following: SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, SQLSRV_PARAM_INOUT. The default valueis SQLSRV_PARAM_IN.
$params = array(
    array($vusername, SQLSRV_PARAM_IN),
    array($vpassword, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_query($conn, $sql, $params);
if( $stmt === false ) {
    echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
    exit;
}
if( $stmt === false ) {
    echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
    exit;
}
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    $vusername = $row['username'];
    $vpassword = $row['password'];
}
'''

扫码关注云+社区

领取腾讯云代金券