Move Blob class to Rdbms namespaces
[mediawiki.git] / includes / libs / rdbms / encasing / MssqlBlob.php
blobaacdf402f49bba3eb15fcda6fbe153a128149022
1 <?php
3 namespace Wikimedia\Rdbms;
5 class MssqlBlob extends Blob {
6 /** @noinspection PhpMissingParentConstructorInspection */
8 /**
9 * @param string $data
11 public function __construct( $data ) {
12 if ( $data instanceof MssqlBlob ) {
13 return $data;
14 } elseif ( $data instanceof Blob ) {
15 $this->mData = $data->fetch();
16 } elseif ( is_array( $data ) && is_object( $data ) ) {
17 $this->mData = serialize( $data );
18 } else {
19 $this->mData = $data;
23 /**
24 * Returns an unquoted hex representation of a binary string
25 * for insertion into varbinary-type fields
26 * @return string
28 public function fetch() {
29 if ( $this->mData === null ) {
30 return 'null';
33 $ret = '0x';
34 $dataLength = strlen( $this->mData );
35 for ( $i = 0; $i < $dataLength; $i++ ) {
36 $ret .= bin2hex( pack( 'C', ord( $this->mData[$i] ) ) );
39 return $ret;