• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

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 Web.data where WebSiteEncryptedKey=HashBytes('SHA1',N'$webencryptedkey')";
     echo $result;
     echo "<br />";
     $rows = $db->query($result);
     } else {
          echo $rows; // line 102
SELECT WebSiteEncryptedKey FROM Web.data 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 Kroger
Jerry Kroger
2 Solutions
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 
FROM Web.data 

Open in new window

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now