简体   繁体   English

资源ID nvarchar(MAX)

[英]Resource ID nvarchar(MAX)

I can't seem to get a straight answer on this. 我似乎无法对此直接回答。

I am fetching the contents of a field which is of type nvarchar(MAX) in the SQLSRV database however I keep getting "Resource id #1" when I echo the result of a field returned from a query instead of the contents. 我正在获取SQLSRV数据库中nvarchar(MAX)类型的字段的内容,但是当我回显从查询返回的字段的结果而不是内容时,我不断得到“资源ID#1”。 I am fairly new to SQLSRV and PHP but from what I understand is this value a pointer to somewhere else where the actually contents I need is? 我对SQLSRV和PHP相当陌生,但是据我所知,此值是指向我实际需要的其他内容的指针吗?

If so how do I get to this data. 如果是这样,我如何获得这些数据。

I have tried: 我努力了:

$sql = "SELECT * FROM table";
    $stmt= sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_STATIC));

$getNext = sqlsrv_fetch($stmt);
$result = sqlsrv_get_field($stmt, 1); // this is the nvarchar(max) field

echo $result; // this shows Resource id #1;

// I tried
//$resource = sqlsrv_fetch($result); // this creates errors

Thank You. 谢谢。

NVARCHAR(MAX) will handle storage concerns for you, storing anything less approx 4000 chars in the table but anything greater in a separate location with a pointer in the table. NVARCHAR(MAX)将为您处理存储问题,将小于4000个字符的任何内容存储在表中,将大于4000个字符的任何内容存储在表中带有指针的单独位置中。 The good news is that SQL Server presents the data returned back to you as if it was stored in the table so the usage of NVARCHAR(MAX) shouldn't be the cause of your problem, it just works like a normal table field. 好消息是,SQL Server会将返回的数据呈现给您,就像存储在表中一样,因此使用NVARCHAR(MAX)不应成为问题的原因,它就像普通的表字段一样工作。

Just found this, may help... 刚发现这个,可能会有所帮助...

/*Get the second field of the row as a stream.
Because the default return type for a nvarchar field is a
string, the return type must be specified as a stream. */
$stream = sqlsrv_get_field( $stmt, 1, 
                            SQLSRV_PHPTYPE_STREAM( SQLSRV_ENC_CHAR));
while( !feof( $stream))
{ 
    $str = fread( $stream, 10000);
    echo $str;
}

http://msdn.microsoft.com/en-us/library/cc296207(v=sql.105).aspx http://msdn.microsoft.com/en-us/library/cc296207(v=sql.105).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM