PHP select query on MS SQL SERVER 12

My client has a MS SQL Server 12 database table with a column - binary(8000)
It is populated with HashBytes('SHA1', '[concatenation of nvarchar entries of several other columns]').
Sample value is: 0x6C44CFB1C32C6E4ECDEBAC863FD5EA345681AC18

Using PHP 5.6.6, I collect the needed info to duplicate the concatenation described above and use the info to try to convert to an encryption to match the MS SQL SERVER 12 entry.
Nothing has worked yet  - I've tried many variations of a select statement like this one:
     $result="SELECT WebSiteEncryptedKey FROM where WebSiteEncryptedKey=HashBytes('SHA1',N'$webencryptedkey')";
     echo $result;
     echo "<br />";
     $rows = $db->query($result);
     } else {
          echo $rows; // line 102
SELECT WebSiteEncryptedKey FROM where WebSiteEncryptedKey=HashBytes('SHA1',N'CURVATURESFP-10G-LR-CURV1154263')

Catchable fatal error: Object of class PDOStatement could not be converted to string in D:\inetpub\wwwroot\Registration.php on line 102

Any help with doing this the correct way will be appreciated very much.
Thank you,
Jerry KrogerCTO - FounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
2 things:
1) you may want to cast the WebSiteEncryptedKey column to nvarchar(max) in the comparison
2) the error says $row is a PDOStatement (which is an associate result set after query executed) and cannot use echo to output such data type.
Vitor MontalvãoMSSQL Senior EngineerCommented:
You can't compare Binaries values. You'll need to perform a conversion to VARCHAR so you can compare the values. Maybe something like:
SELECT WebSiteEncryptedKey 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jerry KrogerCTO - FounderAuthor Commented:
Thank you Brian, and thank you Vitor.
Both comments were spot on.
Vitor, your detailed example was just what I needed to understand  the concept.

Again thanks to each of you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.