Skip to content

Commit

Permalink
Test: Streaming with char encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
v-kigos authored Jan 28, 2017
1 parent 78598fc commit 144ad43
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/sqlsrv/srv_013_sqlsrv_get_field.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--TEST--
sqlsrv_get_field() using SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR)
--SKIPIF--
--FILE--
<?php

require_once("autonomous_setup.php");

// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }

// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();

// Create table
$query = "CREATE TABLE ".$tableName." (ID NVARCHAR(10))";
$stmt = sqlsrv_query($conn, $query);

// Insert data
$query = "INSERT INTO ".$tableName." VALUES ('1998.1'),('-2004.2436'),('4.2 EUR')";
$stmt = sqlsrv_query($conn, $query) ?: die( print_r( sqlsrv_errors(), true) );

// Fetch data
$query = "SELECT * FROM ".$tableName;
$stmt = sqlsrv_query( $conn, $query ) ?: die( print_r( sqlsrv_errors(), true) );

while(sqlsrv_fetch($stmt)) {
$field = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
var_dump($field);

while(!feof($field))
{
echo fread($field, 100)."\n";
}
}

// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);

// Close connection
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"
?>

--EXPECT--
resource(10) of type (stream)
1998.1
resource(11) of type (stream)
-2004.2436
resource(12) of type (stream)
4.2 EUR
Done

0 comments on commit 144ad43

Please sign in to comment.