odbc_fetch_array上的PHP字符串限制 [英] PHP String Limitation On odbc_fetch_array

查看:114
本文介绍了odbc_fetch_array上的PHP字符串限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下sql

SELECT
bw_imp_step as imp_action,   
FROM cm3rm1 m1 INNER JOIN cm3rm2 m2 ON m1.number=m2.number
WHERE m1.number='$id'

在DbVisualizer中返回相同的查询时,它返回整个字符串,但是在我的php中运行相同的查询会限制该字符串并将其切到末尾.

when this same query is returned in DbVisualizer it returns the entire string however running this same query in my php limits the string and cuts it off towards the end.

返回的字符串大约为5500个字符.

The string that is returned is roughly 5500 characters.

下面是运行上述查询的php脚本:

Below is the php script that runs the above query:

$connection = odbc_connect("Driver={SQL  Server};Provider=SQLNCLI;Server=sname;Database=cbname;","username","password")

$sql = "SELECT
bw_imp_step as imp_action, 
FROM cm3rm1 m1 INNER JOIN cm3rm2 m2 ON m1.number=m2.number
WHERE m1.number='$id'";
$result = odbc_exec ($connection,$sql);

if ($row = odbc_fetch_array($result){
   $imp_action = $row["imp_action"];
}

当我将$ imp_action放到页面甚至文件中时,它会在5000个字符左右截断字符串.

When I put put $imp_action to the page or even to a file it cuts off the string at around 5000charactes.

所以我的问题是:PHP是否限制结果集返回的字符串的大小?我已经读过php可以处理2GB的字符串大小,而这个字符串甚至不接近该大小.

So my question is: Does PHP limit the size of a string being returned by a resultset? I have read that php can handle a string size of 2GB and this string is not even close to that size.

推荐答案

我知道这是一篇过时的文章,但是我也碰到了这一点,而且情况非常复杂,无法提供完整的答案.

I know this is an old post, but I just ran into this too and the situation was sufficiently complex to warrant a complete answer.

在某些地方您的数据可能会被截断.

There are several places where the your data could be getting truncated.

ODBC长读取长度

ODBC对于大列具有默认的长读取长度(lrl).通过执行以下操作之一,确保获取的lrl足够大:

ODBC has a default long read length (lrl) for large columns. Make sure the lrl for your fetch is sufficiently large, by doing one of the following:

  • php.ini中的默认值设置为更大的值,例如odbc.defaultlrl = 10000.

  • Set the default in php.ini to something bigger, like odbc.defaultlrl = 10000.

或使用ini_set("odbc.defaultlrl", "10000");在进行连接之前 中将其设置在您的代码中.

Or use ini_set("odbc.defaultlrl", "10000"); to set it in your code before making your connection.

或在获取结果之前使用odbc_longreadlen($result, "10000");在代码中进行设置.

Or use odbc_longreadlen($result, "10000"); to set it in your code before fetching your result.

FreeTDS

如果您正在使用FreeTDS从Linux环境连接到MS SQL DB,则在freetds.conf文件中设置了text size限制.在这里仔细检查您的配置是否足够大.

If you're using FreeTDS to connect to an MS SQL DB from a Linux environment, there's a text size limit set in your freetds.conf file. Double check that your configuration is large enough here.

php_mssql

就像@Anujan的回答一样,有些人(我认为不是OP)正在使用php_mssql建立连接,在这种情况下,您要确保mssql.textlimitmssql.textsize足够大,通过在php.ini中进行设置或在代码中进行以下设置(在建立连接之前):

As in @Anujan's answer, some people (not the OP, I think) may be using php_mssql to make their connection, in which case you want to make sure your mssql.textlimit and mssql.textsize are sufficiently large, either by settings them in your php.ini or with the following in your code (before making your connection):

ini_set('mssql.textlimit', "10000");
ini_set('mssql.textsize', "10000");

SQL Server

SQL Server本身设置了默认的文本大小,您可能需要显式提高它的大小(特别是如果使用不带php_mssql的ODBC和上面指定的配置).在这种情况下,请将以下内容添加到查询字符串的开头:

The SQL Server itself sets a default text size and you may need to explicitly bump it up (especially if using ODBC without php_mssql and the configuration given for it above). In this case, add the following to the beginning of your query string:

SET TEXTSIZE 10000
SELECT big_ol_column FROM wherever
...

请注意,某些更改(例如对php.ini的更改)可能要求您重新加载/重新启动PHP/Nginx/Apache才能生效.

Note that some changes (like to php.ini) may require you to reload/restart PHP/Nginx/Apache to take effect.

通过查看截断的结果大小,您应该能够找出其中哪些限制了结果.对我来说,所有内容都恢复了4096个字符的长度,因此我设置了新的上限.

You should be able to figure out which of these is capping your result by looking at your truncated result size. For me, everything kept coming back 4096 characters long, so I new whatever was capping me was set to that.

还要注意,上面的示例中的"10000"不是一个神奇的数字,请对其进行调整以适合您的需求.

Also note that "10000" in the example above is not a magic number—adjust it to suit your needs.

这篇关于odbc_fetch_array上的PHP字符串限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆