Link to home
Create AccountLog in
Avatar of Jerry Kroger
Jerry KrogerFlag for United States of America

asked on

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);
     if(!$rows)
     {
          die($db->errorInfo());
     } else {
          echo $rows; // line 102
     }
/*
RESULTS:
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,
softexecware
SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Jerry Kroger

ASKER

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.
softexecware