@@ -17,6 +17,7 @@ function bindTypeNoEncoding($conn, $sql, $input)
17
17
$ stmt ->setAttribute (constant ('PDO::SQLSRV_ATTR_ENCODING ' ), PDO ::SQLSRV_ENCODING_BINARY );
18
18
$ stmt ->bindParam (2 , $ input , PDO ::PARAM_LOB );
19
19
$ stmt ->execute ();
20
+ echo "bindTypeNoEncoding: expected to fail! \n" ;
20
21
} catch (PDOException $ e ) {
21
22
$ error = '*An encoding was specified for parameter 1. Only PDO::PARAM_LOB and PDO::PARAM_STR can take an encoding option. ' ;
22
23
if (!fnmatch ($ error , $ e ->getMessage ())) {
@@ -36,6 +37,7 @@ function bindDefaultEncoding($conn, $sql, $input)
36
37
$ stmt ->setAttribute (constant ('PDO::SQLSRV_ATTR_ENCODING ' ), PDO ::SQLSRV_ENCODING_BINARY );
37
38
$ stmt ->bindParam (2 , $ input , PDO ::PARAM_LOB );
38
39
$ stmt ->execute ();
40
+ echo "bindDefaultEncoding: expected to fail! \n" ;
39
41
} catch (PDOException $ e ) {
40
42
$ error = '*Invalid encoding specified for parameter 1. ' ;
41
43
if (!fnmatch ($ error , $ e ->getMessage ())) {
@@ -52,8 +54,9 @@ function insertData($conn, $sql, $input)
52
54
53
55
$ stmt = $ conn ->prepare ($ sql );
54
56
$ stmt ->bindParam (1 , $ value );
55
- $ stmt ->setAttribute (constant ('PDO::SQLSRV_ATTR_ENCODING ' ), PDO ::SQLSRV_ENCODING_BINARY );
56
- $ stmt ->bindParam (2 , $ input , PDO ::PARAM_LOB );
57
+ // Specify binary encoding for the second parameter only such that the first
58
+ // parameter is unaffected
59
+ $ stmt ->bindParam (2 , $ input , PDO ::PARAM_LOB , 0 , PDO ::SQLSRV_ENCODING_BINARY );
57
60
$ stmt ->execute ();
58
61
} catch (PDOException $ e ) {
59
62
echo "Error unexpected in insertData \n" ;
@@ -68,6 +71,7 @@ function invalidEncoding1($conn, $sql)
68
71
$ stmt ->bindColumn (1 , $ id , PDO ::PARAM_INT , 0 , PDO ::SQLSRV_ENCODING_UTF8 );
69
72
$ stmt ->execute ();
70
73
$ stmt ->fetch (PDO ::FETCH_BOUND );
74
+ echo "invalidEncoding1: expected to fail! \n" ;
71
75
} catch (PDOException $ e ) {
72
76
$ error = '*An encoding was specified for column 1. Only PDO::PARAM_LOB and PDO::PARAM_STR column types can take an encoding option. ' ;
73
77
if (!fnmatch ($ error , $ e ->getMessage ())) {
@@ -84,6 +88,7 @@ function invalidEncoding2($conn, $sql)
84
88
$ stmt ->bindColumn ('Value ' , $ val1 , PDO ::PARAM_LOB , 0 , PDO ::SQLSRV_ENCODING_DEFAULT );
85
89
$ stmt ->execute ();
86
90
$ stmt ->fetch (PDO ::FETCH_BOUND );
91
+ echo "invalidEncoding2: expected to fail! \n" ;
87
92
} catch (PDOException $ e ) {
88
93
$ error = '*Invalid encoding specified for column 1. ' ;
89
94
if (!fnmatch ($ error , $ e ->getMessage ())) {
@@ -100,6 +105,7 @@ function invalidEncoding3($conn, $sql)
100
105
$ stmt ->bindColumn (1 , $ id , PDO ::PARAM_STR , 0 , "dummy " );
101
106
$ stmt ->execute ();
102
107
$ stmt ->fetch (PDO ::FETCH_BOUND );
108
+ echo "invalidEncoding3: expected to fail! \n" ;
103
109
} catch (PDOException $ e ) {
104
110
$ error = '*An invalid type or value was given as bound column driver data for column 1. Only encoding constants such as PDO::SQLSRV_ENCODING_UTF8 may be used as bound column driver data. ' ;
105
111
if (!fnmatch ($ error , $ e ->getMessage ())) {
0 commit comments