Page 1 of 1
PHP handling of Sybase date data unexpected
Posted: Fri Jun 08, 2007 12:50 pm
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:
The Sybase client showed
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?
Posted: Fri Jun 08, 2007 1:10 pm
by Benjamin
Probably has something to do with the 6.
Posted: Fri Jun 08, 2007 1:22 pm
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.
Posted: Fri Jun 08, 2007 1:29 pm
by Benjamin
Can you run the proc or query from a terminal and see what sybase is returning?
Posted: Fri Jun 08, 2007 3:22 pm
by RobertGonzalez
From the CLI Sybase is returning
There are two spaces between month and the day if the day single digit.
Posted: Fri Jun 08, 2007 4:40 pm
by Benjamin
I would assume there is something in the PHP code truncating it.
Posted: Fri Jun 08, 2007 5:02 pm
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).
Posted: Fri Jun 08, 2007 5:09 pm
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..
Posted: Fri Jun 08, 2007 5:11 pm
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.