2

I'm fetching some data from an MSSQL table using the mssql_fetch_object, but the text appears to cut off on the page.

The data is all there in the table, but it seems to cut off in the view page.

Has anyone else encountered this problem and perhaps knows of a workaround? Here is my code;

<?php include('includes/session.php');
$query = "SELECT content FROM pages WHERE id = '11'";
$result = mssql_query($query);
$page = mssql_fetch_object($result);
?>

<div id="leftcol">
<?php echo stripslashes($page->content) ?>
</div>
4
  • Why stripslashes? Data comes out of the database raw, all you have to do to put it on the page is htmlspecialchars() it (assuming it's text and not already HTML). Commented Oct 1, 2009 at 14:38
  • @bobince The content has some formatting in it as we are using the CK Editor. However, the content still seems to get cut off in the view page even when we don't use stripslashes. :S Commented Oct 1, 2009 at 15:10
  • I would suggest doing a VAR_DUMP() to see whats being returned echo var_dump($page->content); Commented Oct 1, 2009 at 17:05
  • 1
    Hey Phill, the VAR_DUMP() returned string(4096) " to the end of the initial text, cutting the text off in the word 'to'. Commented Oct 2, 2009 at 8:40

5 Answers 5

4

I'm not familiar with using mssql in php, but I just tried an example using mysql without problem.

This looks suspicious to me

VAR_DUMP() returned string(4096)

so I did some googling and found this link

http://www.bram.us/2007/07/05/my-dotd-ms-sql-vs-php-4096-is-the-default-limit/

It suggests to change mssql.textlimit and mssql.textsize to 1048576 (which is 2ˆ20) in your php.ini as the default is 4096. Hope that helps.

php.ini

  ; Valid range 0 - 2147483647.  Default = 4096.
  mssql.textlimit = 1048576
  ; Valid range 0 - 2147483647.  Default = 4096.
  mssql.textsize = 1048576
Sign up to request clarification or add additional context in comments.

Comments

2

Is it a VARCHAR field? http://docs.php.net/mssql_field_length says:

Note: Note to Windows Users
Due to a limitation in the underlying API used by PHP (MS DBLib C API), the length of VARCHAR fields is limited to 255. If you need to store more data, use a TEXT field instead.

1 Comment

@VolkerK The data type is TEXT, which is odd why the characters are being cut off. :S
0

try a strlen() on the data and compare the length to the data within the database. It should give you some indication of where the problem is (db or php)

Comments

0

Try to set

mssql.textlimit = 10000000
mssql.textsize  = 10000000

in your php.ini or set it with ini_set('mssql.textlimi', 10000000);

Comments

0

I have silimar issue when i use PHP to direct connect to MS SQL, and data type Varchar only retrieve up to 255 charactors. the issue solve by convert the data type to text under the query, and it works for now.

eg:

before

select desc from table1

after

select convert(text, desc) as desc from table1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.