1

I have this value:

9F7470D37A5BC44D01C19389578E9372 (is a password) and i want to insert it in a varbinary column.

This is my script, but is not working.

$insert = $db->prepare("INSERT INTO Table (password) values (?)");
$insert->execute(array('9F7470D37A5BC44D01C19389578E9372'));

I m getting this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 257 [Microsoft][ODBC SQL Server Driver][SQL Server]Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. (SQLExecute[257] at ext\pdo_odbc\odbc_stmt.c:133)' 

What i m missing?

Mando Madalin
  • 193
  • 2
  • 3
  • 14
  • 1
    Unless it's just a typing error, in the post, on your part `array` in the statement `$insert->execute(arrray('9F7470D37A5BC44D01C19389578E9372'));` is misspelled (extra r) – elitechief21 Jan 23 '14 at 16:24
  • 1
    This `execute(arrray` needs to be `execute(array` wee-bit of a typo ;-) You can leave it in there if it's time for `Rrrrroll up the Rrrim to Win` ;-) – Funk Forty Niner Jan 23 '14 at 16:24
  • 1
    _Implicit conversion from data type varchar to varbinary is not allowed._ seems pretty clear. See [this question](http://stackoverflow.com/questions/17135157/change-data-type-varchar-to-varbinarymax-in-sql-server) for info on how to modify your query. – Michael Berkowski Jan 23 '14 at 16:25
  • @elitechief21 sorry, that was a misspelling error, script is fine. – Mando Madalin Jan 23 '14 at 16:26
  • 1
    As is said here http://stackoverflow.com/questions/3275548/what-data-can-be-stored-in-varbinary-data-type-of-sql-server - " To store a string in a varbinary column, you'd have to cast it to varbinary" – Unix von Bash Jan 23 '14 at 16:28
  • And that is why we have guys like @MichaelBerkowski to come 'rrrround and save us from having egg in our face ;-) Speaking of which, it's almost lunch time! – Funk Forty Niner Jan 23 '14 at 16:28

0 Answers0