You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 93e2ceb
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/connect/php/pdostatement-getcolumnmeta.md
+63-1Lines changed: 63 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "PDOStatement::getColumnMeta | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "01/19/2017"
4
+
ms.date: "01/31/2020"
5
5
ms.prod: sql
6
6
ms.prod_service: connectivity
7
7
ms.reviewer: ""
@@ -63,6 +63,68 @@ print $metadata['name'];
63
63
?>
64
64
```
65
65
66
+
## Sensitivity Data Classification Metadata
67
+
68
+
Beginning with version 5.8.0, a new statement attribute `PDO::SQLSRV_ATTR_DATA_CLASSIFICATION` is available for users to access the [sensitivity data classification metadata](https://docs.microsoft.com/sql/relational-databases/security/sql-data-discovery-and-classification?view=sql-server-ver15&tabs=t-sql#subheading-4) in Microsoft SQL Server 2019 using `PDOStatement::getColumnMeta`, which requires Microsoft ODBC Driver 17.4.2 or above.
69
+
70
+
Note the attribute `PDO::SQLSRV_ATTR_DATA_CLASSIFICATION` is `false` by default, but when set to `true`, the aforementioned array field, `flags`, will be populated with the sensitivity data classification metadata, if exists.
71
+
72
+
Take a Patients table for example:
73
+
74
+
```
75
+
CREATE TABLE Patients
76
+
[PatientId] int identity,
77
+
[SSN] char(11),
78
+
[FirstName] nvarchar(50),
79
+
[LastName] nvarchar(50),
80
+
[BirthDate] date)
81
+
```
82
+
83
+
We can classify the SSN and BirthDate columns as shown below:
84
+
85
+
```
86
+
ADD SENSITIVITY CLASSIFICATION TO [Patients].SSN WITH (LABEL = 'Highly Confidential - GDPR', INFORMATION_TYPE = 'Credentials')
87
+
ADD SENSITIVITY CLASSIFICATION TO [Patients].BirthDate WITH (LABEL = 'Confidential Personal Data', INFORMATION_TYPE = 'Birthdays')
88
+
```
89
+
90
+
To access the metadata, use `PDOStatement::getColumnMeta` by setting `PDO::SQLSRV_ATTR_DATA_CLASSIFICATION` to true, as shown in the snippet below:
{"flags":{"Data Classification":[{"Label":{"name":"Confidential Personal Data","id":""},"Information Type":{"name":"Birthdays","id":""}}]},"sqlsrv:decl_type":"date","native_type":"string","table":"","pdo_type":2,"name":"BirthDate","len":10,"precision":0}
115
+
```
116
+
117
+
If we modify the above snippet by setting `PDO::SQLSRV_ATTR_DATA_CLASSIFICATION` to `false` (the default case), the `flags` field will always be `0` as before, like this:
Copy file name to clipboardExpand all lines: docs/connect/php/pdostatement-setattribute.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "PDOStatement::setAttribute | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "04/22/2019"
4
+
ms.date: "01/31/2020"
5
5
ms.prod: sql
6
6
ms.prod_service: connectivity
7
7
ms.reviewer: ""
@@ -36,6 +36,7 @@ The following table contains the list of available attributes:
36
36
|Attribute|Values|Description|
37
37
|-------------|----------|---------------|
38
38
|PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE|1 to the PHP memory limit.|Configures the size of the buffer that holds the result set for a client-side cursor.<br /><br />The default is 10,240 KB (10 MB).<br /><br />For more information about client-side cursors, see [Cursor Types (PDO_SQLSRV Driver)](../../connect/php/cursor-types-pdo-sqlsrv-driver.md).|
39
+
|PDO::SQLSRV_ATTR_DATA_CLASSIFICATION|true or false|Specifies whether to retrieve data classification metadata when calling [PDOStatement::getColumnMeta](../../connect/php/pdostatement-getcolumnmeta.md). The default is false.|
39
40
|PDO::SQLSRV_ATTR_DECIMAL_PLACES|Integer between 0 and 4 (inclusive)|Specifies the number of decimal places when formatting fetched money values.<br /><br />Any negative integer or value more than 4 will be ignored.<br /><br />This option works only when PDO::SQLSRV_ATTR_FORMAT_DECIMALS is true.<br /><br />This option may also be set at the connection level. If so, then this option overrides the connection level option.<br /><br />For more information, see [Formatting Decimal Strings and Money Values (PDO_SQLSRV Driver)](../../connect/php/formatting-decimals-pdo-sqlsrv-driver.md).|
40
41
|PDO::SQLSRV_ATTR_ENCODING|Integer<br /><br />PDO::SQLSRV_ENCODING_UTF8 (Default)<br /><br />PDO::SQLSRV_ENCODING_SYSTEM<br /><br />PDO::SQLSRV_ENCODING_BINARY|Sets the character set encoding to be used by the driver to communicate with the server.|
41
42
|PDO::SQLSRV_ATTR_FETCHES_DATETIME_TYPE|true or false|Specifies whether to retrieve date and time types as [PHP DateTime](http://php.net/manual/en/class.datetime.php) objects. If left false, the default behavior is to return them as strings.<br /><br />This option may also be set at the connection level. If so, then this option overrides the connection level option.<br /><br />For more information, see [How to: Retrieve Date and Time Types as PHP DateTime Objects Using the PDO_SQLSRV Driver](../../connect/php/how-to-retrieve-datetime-objects-using-pdo-sqlsrv-driver.md).|
@@ -86,42 +87,150 @@ The Nullable key can either be yes or no.
86
87
## Example
87
88
The following example creates a statement resource, then retrieves and displays the field metadata. The example assumes that SQL Server and the [AdventureWorks](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works) database are installed on the local computer. All output is written to the console when the example is run from the command line.
88
89
89
-
```
90
-
<?php
91
-
/* Connect to the local server using Windows Authentication and
92
-
specify the AdventureWorks database as the database in use. */
$tsql = "SELECT ReviewerName, Comments FROM Production.ProductReview";
104
+
$stmt = sqlsrv_prepare( $conn, $tsql);
105
+
106
+
/* Get and display field metadata. */
107
+
foreach( sqlsrv_field_metadata( $stmt) as $fieldMetadata) {
108
+
foreach( $fieldMetadata as $name => $value) {
109
+
echo "$name: $value\n";
110
+
}
111
+
echo "\n";
114
112
}
115
113
116
-
/* Note: sqlsrv_field_metadata can be called on any statement
117
-
resource, pre- or post-execution. */
118
-
119
-
/* Free statement and connection resources. */
120
-
sqlsrv_free_stmt( $stmt);
121
-
sqlsrv_close( $conn);
122
-
?>
123
-
```
114
+
/* Note: sqlsrv_field_metadata can be called on any statement
115
+
resource, pre- or post-execution. */
124
116
117
+
/* Free statement and connection resources. */
118
+
sqlsrv_free_stmt($stmt);
119
+
sqlsrv_close($conn);
120
+
?>
121
+
```
122
+
123
+
## Sensitivity Data Classification Metadata
124
+
125
+
A new option `DataClassification` is introduced in version 5.8.0 for users to access the [sensitivity data classification metadata](https://docs.microsoft.com/sql/relational-databases/security/sql-data-discovery-and-classification?view=sql-server-ver15&tabs=t-sql#subheading-4) in Microsoft SQL Server 2019 using `sqlsrv_field_metadata`, which requires Microsoft ODBC Driver 17.4.2 or above.
126
+
127
+
By default, the option `DataClassification` is `false`, but when set to `true`, the array returned by `sqlsrv_field_metadata` will be populated with the sensitivity data classification metadata, if exists.
128
+
129
+
Take a Patients table for example:
130
+
131
+
```
132
+
CREATE TABLE Patients
133
+
[PatientId] int identity,
134
+
[SSN] char(11),
135
+
[FirstName] nvarchar(50),
136
+
[LastName] nvarchar(50),
137
+
[BirthDate] date)
138
+
```
139
+
140
+
We can classify the SSN and BirthDate columns as shown below:
141
+
142
+
```
143
+
ADD SENSITIVITY CLASSIFICATION TO [Patients].SSN WITH (LABEL = 'Highly Confidential - GDPR', INFORMATION_TYPE = 'Credentials')
144
+
ADD SENSITIVITY CLASSIFICATION TO [Patients].BirthDate WITH (LABEL = 'Confidential Personal Data', INFORMATION_TYPE = 'Birthdays')
145
+
```
146
+
147
+
To access the metadata, invoke `sqlsrv_field_metadata` as shown in the snippet below:
{"Name":"BirthDate","Type":91,"Size":null,"Precision":10,"Scale":0,"Nullable":1,"Data Classification":[{"Label":{"name":"Confidential Personal Data","id":""},"Information Type":{"name":"Birthdays","id":""}}]}
232
+
```
233
+
125
234
## See Also
126
235
[SQLSRV Driver API Reference](../../connect/php/sqlsrv-driver-api-reference.md)
0 commit comments