PHP mssql question
Posted: Sat Oct 02, 2010 2:55 pm
Hi all.
I am trying to use php to connect to a mssql express database and display an image. I used the following code.
$conn = mssql_connect('SHEN-PC\SQLEXPRESS', 'user', 'pass');
if (!$conn) {
die('Something went wrong while connecting to MSSQL');
}
$query = mssql_query('SELECT [Photo] FROM [social].[dbo].[Employers] where [Id] = 10');
header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename="downloaded.jpg"');
// Check if there were any records
if (!mssql_num_rows($query)) {
echo 'No records found.';
} else {
// The following is equal to the code below:
//
// while ($row = mssql_fetch_row($query)) {
while ($row = mssql_fetch_object($query)) {
// ...
echo $row->Photo;
}
}
// Free the query result
mssql_free_result($query);
however, only the top 1/3 of the image got displayed..... I tried to print it out without header, and the raw code seems to be the same length regardless of what image i pull. so I think it might be because mssql didn't extract all the data? Can any one help me to figure out what s wrong with my code?
I am trying to use php to connect to a mssql express database and display an image. I used the following code.
$conn = mssql_connect('SHEN-PC\SQLEXPRESS', 'user', 'pass');
if (!$conn) {
die('Something went wrong while connecting to MSSQL');
}
$query = mssql_query('SELECT [Photo] FROM [social].[dbo].[Employers] where [Id] = 10');
header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename="downloaded.jpg"');
// Check if there were any records
if (!mssql_num_rows($query)) {
echo 'No records found.';
} else {
// The following is equal to the code below:
//
// while ($row = mssql_fetch_row($query)) {
while ($row = mssql_fetch_object($query)) {
// ...
echo $row->Photo;
}
}
// Free the query result
mssql_free_result($query);
however, only the top 1/3 of the image got displayed..... I tried to print it out without header, and the raw code seems to be the same length regardless of what image i pull. so I think it might be because mssql didn't extract all the data? Can any one help me to figure out what s wrong with my code?