PHP
$hash = hash('sha256', $string);
Example: correct table definition
sql
ALTER TABLE my_table
ADD COLUMN sha256_hash VARCHAR(64) NOT NULL;
Then populate it with:
sql
UPDATE my_table
SET sha256_hash = CONVERT(VARCHAR(64), HASHBYTES('SHA2_256', plain_string_field), 2);
This produces uppercase hex, which is fully compatible with PHP’s lowercase hex.
✔ Final recommendation
Use VARCHAR(64) for storing SHA‑256 hashes generated by PHP.