24, July 2008

PDO MSSQL query result field limited to 255 chars - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: PDO MSSQL query result field limited to 255 chars
« previous next »
Pages: [1] Print

Author Topic: PDO MSSQL query result field limited to 255 chars  (Read 539 times)
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« on: Sep 08, 2007, 12:04:17 PM »

Win XP Sp2
IIS
MSSQL Server Express 2005
PHP 5.2.3

I am using PDO with the MSSQL database but I have a problem which I think must be a setting somewhere that I have missed. The FULL_DESC field in the database is a VARCHAR(5000) and appears fine when I query it throught the Server Management Studio Express. When I copy it from the table, it is the correct length (which is 3000 chars).

I want to query it and display it on my web page but it is being truncated at 255 chars.

Before I show the code I am using, I just want to say that I have tried setting mssql.textsize = 4096 & mssql.textlimit = 4096 in the php.ini file and restarting the IIS server but no difference.

I cannot help feeling a fool and feeling I have missed something obvious. Any ideas please?

obviously the connection to the db has been established before this code.
Code:
    try {
       foreach ($dbh->query("SELECT FULL_DESC FROM PROJECT WHERE PROJECT_ID = '2'") as $row) {
          echo "<BR>".strlen($row['FULL_DESC'])."-".$row['FULL_DESC'];
       }
       $dbh = null;
    } catch (PDOException $e) {
       print "Error!: " . $e->getMessage() . "<br/>";
       die();
    }
    exit;
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #1 on: Sep 08, 2007, 01:58:54 PM »

I am afraid you wont find a solution here as most of us are dedicated to open source technologies (eg. mysql)

The only thing I can think of is that your db class is truncating the data

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #2 on: Sep 08, 2007, 02:19:58 PM »

I dont think it is a MSSQL problem because, as I said, the query analyser shows the full string in the database. I think it is more a PHP setting that I have forgotten or overlooked, or it might be a problem with the PDO code. However, if it is a problem with the PDO code then someone else must have found it by now.

Since PDO is an standard loadable extension to PHP. I thought someone on this PHP forum might be able to spot what I have missed.
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Sep 08, 2007, 02:30:16 PM »

I remember the last Zend conference that one of the speakers told us that PDO has some problems.

try PHP functions for MSsql


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #4 on: Sep 08, 2007, 02:32:26 PM »

First this is an experimental extension. Then looking at your code, looks a little wrong. Try to replace it with this :

Code:
       $res = $dbh->prepare("SELECT FULL_DESC FROM PROJECT WHERE PROJECT_ID = '2'");
       $res->execute();
       while ( $row = $res->fetch() ) {
          var_dump($row);

Hope that works Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Sep 08, 2007, 02:39:38 PM »

First this is an experimental extension. Then looking at your code, looks a little wrong. Try to replace it with this :

yeah some experimental extension which is part for the zend certification Sad


Last blog : 4th of July Lottery from TemplateMonster.com
I crack Photoshop!
*
Posts: 3
22 credits
Members referred : 0


« Reply #6 on: Sep 08, 2007, 03:00:50 PM »

I have tried that other code, and the same thing appears. Still truncated at 255 chars.

When I do a SELECT LEN(FULL_DESC) AS LNGTH.... and then echo $row['LNGTH'] it reports the correct length.

It is  looking as if I will have to use the mssql statements but I was trying not to use anything too specific to MSSQL. However, the SQL statements are slightly different in some areas to mySQL so I would have to change them if I started to use mySQL anyway. It means going through all my programs and changing the code which I was hoping not to do. How does anyone else develop webapps that can use either mySQL or MSSQL - it must be full of 'if' statements!



Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6280
38506 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Sep 08, 2007, 03:57:38 PM »

there are several (better) database abstraction classes (check pear)


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7974
40801 credits
Members referred : 3



« Reply #8 on: Sep 08, 2007, 04:15:29 PM »

The different is mostly to the LIMIT statement. I think there is a db class that do the changes for you. I am not sure but the DB PEAR package has this ability.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7080
Tags : PDO MSSQL query results Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: PDO MSSQL query result field limited to 255 chars
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 24, 2008, 06:37:49 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.708
Total Topics: 7.375
Total Members: 3.705
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: jino@webdco.com

27 Guests, 5 Users online :

13 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.