PHP handling of Sybase date data unexpected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

PHP handling of Sybase date data unexpected

Post by RobertGonzalez »

So I was handling some data from a return set of a Sybase stored procedure the other day and I noticed that in a certain date field I was receiving:

Code: Select all

(string) (6) "Feb   "
The Sybase client showed

Code: Select all

Feb  3 2007
Does anyone know why PHP would truncate a Sybase Date field return data? We fixed this by returning the data as a string type in short format, but I would be interested to know if anyone else has ever had a similar experience in any return set from any database?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Probably has something to do with the 6.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The weird thing is that in the Sybase client, the result is an actual Date datatype in the form Char-Char-Char-space-<space or 0>-Int-space-YYYY. But PHP sees it as a 6 char string with the first three chars as the three chars from the month followed by three spaces and thats it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Can you run the proc or query from a terminal and see what sybase is returning?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

From the CLI Sybase is returning

Code: Select all

Fed  3 2007
There are two spaces between month and the day if the day single digit.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I would assume there is something in the PHP code truncating it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I am taking it straight from the database to the browser. This is the assignment code for the result set (keep in mind we are using an enhanced sybase extension that understands multiple result sets - the core code of the Sybase extension is the same. The only add is the check for multiple result sets).

Code: Select all

<?php
    if ($qry = sybase_query($sql, $con))
    {
        $show_results = true;
        $rs_full = array();
        $counter = 0;
    	
        do {
            $counter++;
            //echo '<h1>We are in a result set ' . $counter . '</h1>';
            while ($row = sybase_fetch_array($qry)) {
                $rs_full[] = $row;
            }
        } while (sybase_next_result($qry));
    
        sybase_free_result($qry);
    }
    else
    {
        echo '<p>There were problems with your query: <strong>' . sybase_get_last_message() . '</strong>';
    }
    
    sybase_close();

if ($show_results) {
    echo '<pre>';
    print_r($rs_full);
    echo '</pre>';
}
?>
Also of note... this is my procedure testing code. I use ADODBlite in production using code similar to this in regards to multiple result sets (I forked that one as well).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Ok so in a terminal it outputs correctly, but in a browser it does not.

Based on the code you provided that doesn't make any sense at all.

This is a long shot from hell..

Code: Select all

$rs_full[] = (string) $row;
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I thought of that too, but by the time the app gets it it is already truncated. This is really odd behavior that I cannot explain at all the DBA.

I cannot think of any special chars in the date type that would tell PHP to stop filling the field at char 6.
Post Reply