Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to convert a string to varbinary in PHP without using the SQL function

I was wondering if it is possible to convert a string to varbinary with PHP to get the same effect as with using the SQL function CONVERT(varbinary, 'data') I would like to do this because I am using codeigniter and would like to use active records for this query, and because of this not directly use a string of SQL, but I need to insert the data into a varbinary field in MS-SQL.

Thanks :)

like image 879
Zen Avatar asked Jan 08 '11 23:01

Zen


1 Answers

you can cast a string as a binary if you are using a recent enough version of PHP.

$binary = (binary)$string;

(binary) casting and b prefix forward support was added in PHP 5.2.1

http://www.php.net/manual/en/language.types.type-juggling.php

like image 193
dqhendricks Avatar answered Oct 17 '22 11:10

dqhendricks