开发者

How do I read a string > 255 chars in php/adodb?

I'm maintaining a web application written in PHP that connects to a MSSQL database.

The original developer used http://adodb.sourceforge.net/ as his database library.

The problem is, when reading data using the GetAll method, all the strings are truncated to 255 chars.

Has anyone a sol开发者_高级运维ution to my problem?

edit: The column I am having a problem with is a varchar(800)


What exactly are you able to change?

I stumbled across this article, which may help: ADODB Varchar Limit Problem

What it seems to suggest you try is:

  1. Change your column type from varchar to text
  2. In the select statement, stipulate a CAST for the column:

i.e.:

select CAST(MyColumn as text) as MyColumn  

The post cites the following two articles, which back up the above

http://php.oregonstate.edu/manual/en/ref.mssql.php#47527

http://php.oregonstate.edu/manual/en/ref.mssql.php#71602

Hope this helps


Can you get the last column seperately using:

SELECT SUBSTRING (longfield,1,200) as Part1, SUBSTRING (longfield,201,200) as Part2, SUBSTRING (longfield,401,200) as Part3, SUBSTRING (longfield,601,200) as Part4

?

You can then glue the columns back together. You might need some special cases for when then string isn't actualy that long.


Try replace all "255" to "800" or "MAX" in drivers\adodb-mssql.inc.

Or just cast it, not change to text datatype , text is deprecated


I don't have problems using ADODB in PHP to query MSSQL. I write queries in the following way:

<?php
// assuming $db is properly configured and connected ADODB database object
$rs = $db->Execute("SELECT ...");
while (!$rs->EOF) {
    print $rs->fields['fieldname'];
    // further processing of row
    $rs->MoveNext(); // move to the next row
}


Check your whether you are using DISTINCT and GROUP BY statements, apparently "truncation occurs on text fields when using DISTINCT and GROUP BY statements because of the overhead of comparing variable length strings as opposed to fixed length strings".

Link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜