Upload image to MSSQL IIS database using PHP

Hello.

I am new to SQL and trying to upload images to SQL database using PHP.

When i run the script, the column “image” just upload this random numbers, like this: 0x74657374.
I have set the Data Type to image.

This is the script i have now:

$image = "image.jpg";

$query = "INSERT INTO dbo.userInformation
		(image)
		VALUES(?)";
$params = array($image);
$result = sqlsrv_query($conn,$query,$params);

sqlsrv_close($conn);

I may be mistaken BUT, does “image.jpg” look like an image to you?

I have never uploaded images to a database before, so i dont know how Data Type: image works. The variable “$image” is the path to the image. I guess i should name the variable “$imagePath”. And yes, this is an image. image.jpg is located at the same folder as this script.

The smart answer is, don’t! Just store the path to the image and keep the image file on the hard drive. You can store the image in the database, but it is complex to do and REALLY easy to corrupt.

2 Likes
Sponsor our Newsletter | Privacy Policy | Terms of Service