Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:47:07+00:00 2026-06-16T17:47:07+00:00

Using PHP and SQLSRV Driver I have to display binary images from an SQL

  • 0
  • Using PHP and SQLSRV Driver

I have to display binary images from an SQL Server database based on patient ID. The patient IDs and images are located in two different databases.

From the first db I query for image IDs based on the Patient ID entered, and add the results into an array(). Then I would like to use this array of IDs to get the images from the second database.

Problem: I get the following error when using the array in the WHERE caluse of my sql statement:

Notice: Array to string conversion in…

I am really lost on this.

The following is my code:

<?php
// ------------------------------------------------------------
// SCANNED IMAGES SEARCH CLASS
// used to retreive binary images from sql server database
// ------------------------------------------------------------

class ScannedImages extends DbConnect {
    // ------------------------------------------------------------
    // PROPERTIES
    // ------------------------------------------------------------
    public $imageOutput = NULL;

    // ------------------------------------------------------------
    // GET SCANNED IMAGE IDS FROM RIS BASED ON PATIENT ID
    // ------------------------------------------------------------
    public function getImagesByPatientId($sentPatientId) {

        // ------------------------------------------------------------
        // 1. GET IMAGE IDS AND PUT THEM IN AN ARRAY
        // ------------------------------------------------------------

        // connect to [[[FusionRIS]]] database
        $conn1 = $this->sqlSrvConnect_2();

        // get image IDs based on patient ID
        $sql1 = "SELECT DocMgtImageID FROM tbDocMgtImagesAffiliations WHERE PatientID = $sentPatientId";
        $stmt1 = sqlsrv_query($conn1, $sql1);

        // exit if there is problem retrieving the data
        if($stmt1 === false) {
            die(var_dump(sqlsrv_errors(), true));
        }

        // image id array
        $imageIdArray = array();

        // loop through the results
        while($row1 = sqlsrv_fetch_array($stmt1, SQLSRV_FETCH_ASSOC)) {
            $imageIdArray[] = $row1['DocMgtImageID'];
        }

        // ------------------------------------------------------------
        // 2. GET IMAGES BASED ON ARRAY OF IMAGE IDS
        // ------------------------------------------------------------

        // connect to [[[DocMgmt]]] database
        $conn2 = $this->sqlSrvConnect_1();

        // get images based on ids in array 33482
        $sql2 = "SELECT ImageData FROM tbDocMgtImages WHERE DocMgtImageID IN ($imageIdArray)";
        $stmt2 = sqlsrv_query($conn2, $sql2);

        // exit if there is problem retrieving the data
        if($stmt2 === false) {
            die(var_dump(sqlsrv_errors(), true));
        }

        // convert binary to image
        function data_uri($file, $mime) {
            $base64 = base64_encode($file);
            return "data:$mime;base64,$base64";
        }

        // counter for image display
        $count = 0;

        // loop through the results
        while($row2 = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_ASSOC)) {
            $count++;
            $this->imageOutput .= '<a href="#"><img src="'. data_uri($row2['ImageData'], 'image/jpeg') .'" alt=""><span>'. $count .'</span></a>';
        }

        // free the statement and connection resources
        sqlsrv_free_stmt($stmt1);
        sqlsrv_close($conn1);

        sqlsrv_free_stmt($stmt2);
        sqlsrv_close($conn2);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:47:08+00:00Added an answer on June 16, 2026 at 5:47 pm

    You can just send a raw array in a query like that. You need to turn it in to the expected string like 1,2,3,....

    $query = sprintf("SELECT ImageData FROM tbDocMgtImages WHERE DocMgtImageID IN (%s)", implode(',', $imageIdArray));
    

    Now i assume these are not user input and are an INTEGER type column in the other DB so quoting shouldnt be necessary, but in other case you would want to make sure you escape each value before imploding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP SQL Server driver - is there a way to kill
I'm using php and sql server 2008 and the SQL Server Driver for PHP
using PHP and MySQL i have grabbed an array of facebook user ids from
I'm using the SQL Server Driver for PHP to connect to an SQL Server
I am using this code to log in to sql server express 2012 <?php
I have to use MS SQL Server 2008 to store data of PHP CAKE
I'm trying to add new entries to an sql database using php, i can
I am using php to connect to my ms sql server. I am using
I am using PHP 5.3.6 on Windows and connecting to a SQL Server 2008
What is the equivalent function for mssql_result, under Microsoft SQL Driver for PHP (sqlsrv)?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.