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?
PHP mssql question
Moderator: General Moderators
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: PHP mssql question
Edit your post and use
Code: Select all
for your code-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP mssql question
Code: Select all
$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);
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP mssql question
ok here is what I found after testing... apparently mssql didn't extract the full data from the database. I tested it by copy the image into an varchar data type and print out the data. The screen shows the same length of data no matter which image I print. Is this because of something I missed to do?
-
williamshen25
- Forum Newbie
- Posts: 10
- Joined: Fri Sep 03, 2010 5:45 pm
Re: PHP mssql question
ok I find it... you need to either include
ini_set ( 'mssql.textlimit' , '2147483647' );
ini_set ( 'mssql.textsize' , '2147483647' );
in the beginning. or set php.ini 's mysql section according to above. just fyi
ini_set ( 'mssql.textlimit' , '2147483647' );
ini_set ( 'mssql.textsize' , '2147483647' );
in the beginning. or set php.ini 's mysql section according to above. just fyi