非常困惑,可能忽略了一些东西,但有些想法将不胜感激!
我有一个查询如下:
$usernamequery = "select username + ' ' + surname as username, userid from users where username + ' ' + surname = '$username'";
$usernamestmt = sqlsrv_query( $conn, $usernamequery);
if( $usernamestmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
while( $obj = sqlsrv_fetch_object( $usernamestmt))
{
echo $username1 = $obj->username;
echo $userid = $obj->userid;
}
它不返回任何东西,但是当我回显 $usernamequery 我得到
select username + ' ' + surname as username, userid from users where username + ' ' + surname = 'Joe Bloggs'
然后当我直接在 SQL 中运行它时,它会返回我期望的结果。
更奇怪的是,当我将 PHP 更改为实际查询时(即
select username + ' ' + surname as username, userid from users where username + ' ' + surname = 'Joe Bloggs'
)
它运行起来就像一个魅力,并返回我期待的结果。
总而言之,我完全糊涂了……!