-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test: Streaming with char encoding #262
Conversation
|
||
// Connect | ||
$conn = sqlsrv_connect( $serverName, $connectionInfo); | ||
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you consider creating a helper method for error handling (die(print_r(sqlsrv_errors...))? Since you create a database, shouldn't you drop database somewhere when errors occur?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); } | ||
|
||
// Create database | ||
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, is a new database necessary?
$stmt = sqlsrv_query($conn, $query) ?: die( print_r( sqlsrv_errors(), true) ); | ||
|
||
// Fetch data | ||
$query = "SELECT * FROM ".$tableName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: $query = "SELECT * FROM $tableName";
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die(); | ||
|
||
// Create table | ||
$query = "CREATE TABLE ".$tableName." (ID NVARCHAR(10))"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason for NVARCHAR when no unicode character is used? Or consider adding a Unicode input value?
$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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Unicode is used, would SQLSRV_ENC_CHAR work?
|
||
// Compare output | ||
$row = sqlsrv_fetch_array($stmt); | ||
echo ($row['c1'] == $data) ? "True\n" : "False\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No trimming necessary? Nice. :) Just curious, have you tried using '===' for comparison?
|
||
// Compare output | ||
$row = sqlsrv_fetch_array($stmt); | ||
echo ($row['c1'] == $data) ? "True\n" : "False\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main diff of this test comparing to the one above is UTF-8 charset right? Are both files saved in the same encoding?
No description provided.