--TEST-- Test insert data and fetch as all possible php types --DESCRIPTION-- Test insert data of most common column types and fetch them all as possible php types. This test requires the Always Encrypted feature. --SKIPIF-- $database, "UID" => $userName, "PWD" => $userPassword); $conn = sqlsrv_connect($server, $options); if (! $conn) { die("Skip Could not connect during SKIPIF!"); } if (!AE\isQualified($conn)) { die("skip AE feature not supported in the current environment."); } ?> --FILE-- forceEncryption($forceEncryption); $columns[] = $anAEcolumn; $columns[] = new AE\ColumnMeta($dataTypes[$i], "c_".$colname, null, true, true); $queryTypes .= "c_"."$colname, "; $queryTypes .= "c_"."$colname"."_AE, "; $valuesString .= "?, ?, "; } $queryTypes = substr($queryTypes, 0, -2).")"; $valuesString = substr($valuesString, 0, -2).")"; $insertQuery = "INSERT INTO $tableName ".$queryTypes." ".$valuesString; } $SQLSRV_PHPTYPE_CONST = array(SQLSRV_PHPTYPE_INT, SQLSRV_PHPTYPE_DATETIME, SQLSRV_PHPTYPE_FLOAT, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR), SQLSRV_PHPTYPE_STREAM("UTF-8"), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_PHPTYPE_STRING("UTF-8") ); // Two constants STRSIZE and LONG_STRSIZE for the string types so we can test // conversion from a shorter type to a longer type $strsize = STRSIZE; $strsize2 = LONG_STRSIZE; $dataTypes = array("binary($strsize)", "varbinary($strsize)", "varbinary(max)", "char($strsize)", "varchar($strsize)", "varchar(max)", "nchar($strsize)", "nvarchar($strsize)", "nvarchar(max)", "datetime", "smalldatetime", "date", "time(5)", "datetimeoffset(5)", "datetime2(5)", "decimal(28,4)", "numeric(32,4)", "float", "real", "bigint", "int", "smallint", "tinyint", "bit", "binary($strsize2)", "varbinary($strsize2)", "char($strsize2)", "varchar($strsize2)", "nchar($strsize2)", "nvarchar($strsize2)", "time", "datetimeoffset", "datetime2", "decimal(32,4)", "numeric(36,4)" ); set_time_limit(0); sqlsrv_configure('WarningsReturnAsErrors', 1); // Connect $connectionInfo = array('CharacterSet'=>'UTF-8', 'ColumnEncryption' => 'Enabled'); $conn = AE\connect($connectionInfo); if (!$conn) { fatalError("Could not connect.\n"); } $tableName = "type_conversion_table"; $columns = array(); $insertQuery = ""; formulateSetupQuery($tableName, $dataTypes, $columns, $insertQuery); $stmt = AE\createTable($conn, $tableName, $columns); if (!$stmt) { fatalError("Failed to create table $tableName\n"); } // The data we test against is in values.php for ($v = 0; $v < sizeof($values); ++$v) { // Each value must be inserted twice because the AE and non-AE column are side by side. $testValues = array(); for ($i=0; $is; if ($diff == 0) { $value = $valueAE; } } if ($valueAE != $value or $valueFromArrayAE != $valueFromArray) { $index = floor($j / 2); echo "Values do not match! PHPType $i Field $dataTypes[$index]\n"; print_r($valueAE); echo "\n--------\n\n"; print_r($value); echo "\n--------\n\n"; print_r($valueFromArrayAE); echo "\n--------\n\n"; print_r($valueFromArray); echo "\n--------\n\n"; print_r(sqlsrv_errors()); echo("Test failed, values do not match.\n"); } } } } } sqlsrv_free_stmt($stmt); sqlsrv_free_stmt($stmt2); $deleteQuery = "TRUNCATE TABLE $tableName"; $stmt = sqlsrv_query($conn, $deleteQuery); if ($stmt == false) { print_r(sqlsrv_errors()); fatalError("Truncate statement failed"); } sqlsrv_free_stmt($stmt); } dropTable($conn, $tableName); sqlsrv_close($conn); echo "Test successful\n"; ?> --EXPECT-- Test successful