我正在处理注册/登录表单,这是我第一次使用SQLSRV(因为Azure数据库)而且我似乎无法找到mysqli_stmt_bind_result
对SQLSRV的平等可能有人帮助我有了这个?
先谢谢你,托马斯
答案 0 :(得分:0)
我认为您的功能是sqlsrv_fetch_array()
。
您可以查看以下简单示例:
<?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;
}
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$vusername = $row['username'];
$vpassword = $row['password'];
}
'''
您可以阅读更多here。