-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--TEST-- | ||
Test another ANSI encoding fr_FR euro locale outside Windows | ||
--DESCRIPTION-- | ||
This file must be saved in ANSI encoding and the required locale must be present | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_unix_ansitests.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
function insertData($conn, $tableName, $inputs) | ||
{ | ||
try { | ||
$tsql = "INSERT INTO $tableName (id, phrase) VALUES (?, ?)"; | ||
$stmt = $conn->prepare($tsql); | ||
|
||
for ($i = 0; $i < count($inputs); $i++) { | ||
$stmt->execute(array($i, $inputs[$i])); | ||
} | ||
} catch( PDOException $e ) { | ||
echo "Failed to insert data\n"; | ||
print_r( $e->getMessage() ); | ||
} | ||
} | ||
|
||
function dropTable($conn, $tableName) | ||
{ | ||
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName"; | ||
$conn->exec($tsql); | ||
} | ||
|
||
require_once('MsSetup.inc'); | ||
|
||
try { | ||
$locale = 'fr_FR@euro'; | ||
setlocale(LC_ALL, $locale); | ||
|
||
$conn = new PDO("sqlsrv:server = $server; database=$databaseName; driver=$driver", $uid, $pwd); | ||
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM); | ||
$tableName = "pdo_ansitest_FR"; | ||
|
||
dropTable($conn, $tableName); | ||
|
||
$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL, [phrase] [varchar](50) NULL)"; | ||
$conn->exec($tsql); | ||
|
||
$inputs = array("À tout à l'heure!", | ||
"Je suis désolé.", | ||
"À plus!", | ||
" Je dois aller à l'école."); | ||
|
||
// Next, insert the strings | ||
insertData($conn, $tableName, $inputs); | ||
|
||
// Next, fetch the strings | ||
$tsql = "SELECT phrase FROM $tableName ORDER by id"; | ||
$stmt = $conn->query($tsql); | ||
|
||
$results = $stmt->fetchAll(PDO::FETCH_NUM); | ||
for ($i = 0; $i < count($inputs); $i++) { | ||
if ($results[$i][0] !== $inputs[$i]) { | ||
echo "Unexpected phrase retrieved:\n"; | ||
var_dump($results[$i][0]); | ||
} | ||
} | ||
|
||
dropTable($conn, $tableName); | ||
|
||
unset($stmt); | ||
unset($conn); | ||
} catch (PDOException $e) { | ||
print_r($e->getMessage()); | ||
} | ||
|
||
echo "Done" . PHP_EOL; | ||
?> | ||
--EXPECT-- | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
die("skip Test for Linux and macOS"); | ||
} | ||
|
||
if (!extension_loaded("pdo_sqlsrv")) { | ||
die("skip Extension not loaded"); | ||
} | ||
|
||
$loc = setlocale(LC_ALL, 'fr_FR@euro'); | ||
if (empty($loc)) { | ||
die("skip required French locale not available"); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
die("skip: Test for Linux and macOS"); | ||
} | ||
|
||
if (!extension_loaded("sqlsrv")) { | ||
die("skip extension not loaded"); | ||
} | ||
|
||
$loc = setlocale(LC_ALL, 'fr_FR@euro'); | ||
if (empty($loc)) { | ||
die("skip required French locale not available"); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--TEST-- | ||
Test another ansi encoding fr_FR euro locale outside Windows | ||
--DESCRIPTION-- | ||
This file must be saved in ANSI encoding and the required locale must be present | ||
--ENV-- | ||
PHPT_EXEC=true | ||
--SKIPIF-- | ||
<?php require('skipif_unix_ansitests.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
function insertData($conn, $tableName, $inputs) | ||
{ | ||
$tsql = "INSERT INTO $tableName (id, phrase) VALUES (?, ?)"; | ||
|
||
$param1 = null; | ||
$param2 = null; | ||
$params = array(&$param1, &$param2); | ||
|
||
$stmt = sqlsrv_prepare($conn, $tsql, $params); | ||
if ($stmt === false) { | ||
echo "Failed to prepare the insert statement\n"; | ||
die(print_r(sqlsrv_errors(), true)); | ||
} | ||
|
||
for ($i = 0; $i < count($inputs); $i++) { | ||
$param1 = $i; | ||
$param2 = $inputs[$i]; | ||
if (!sqlsrv_execute($stmt)) { | ||
echo "Statement could not be executed.\n"; | ||
die(print_r(sqlsrv_errors(), true)); | ||
} | ||
} | ||
} | ||
|
||
function dropTable($conn, $tableName) | ||
{ | ||
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName"; | ||
sqlsrv_query($conn, $tsql); | ||
} | ||
|
||
require_once('MsSetup.inc'); | ||
|
||
$tableName = "srv_ansitest_FR"; | ||
$locale = 'fr_FR@euro'; | ||
setlocale(LC_ALL, $locale); | ||
|
||
$conn = sqlsrv_connect($server, $connectionOptions); | ||
if( $conn === false ) { | ||
echo "Failed to connect\n"; | ||
die(print_r(sqlsrv_errors(), true)); | ||
} | ||
|
||
dropTable($conn, $tableName); | ||
|
||
$tsql = "CREATE TABLE $tableName([id] [int] NOT NULL, [phrase] [varchar](50) NULL)"; | ||
$stmt = sqlsrv_query($conn, $tsql); | ||
|
||
$inputs = array("À tout à l'heure!", | ||
"Je suis désolé.", | ||
"À plus!", | ||
" Je dois aller à l'école."); | ||
|
||
// Next, insert the strings | ||
insertData($conn, $tableName, $inputs); | ||
|
||
// Next, fetch the strings | ||
$tsql = "SELECT phrase FROM $tableName ORDER by id"; | ||
$stmt = sqlsrv_query($conn, $tsql); | ||
if ($stmt === false) { | ||
echo "Failed to run select query\n"; | ||
die(print_r(sqlsrv_errors(), true)); | ||
} | ||
|
||
$i = 0; | ||
while (sqlsrv_fetch($stmt)) { | ||
$phrase = sqlsrv_get_field($stmt, 0); | ||
if ($phrase != $inputs[$i++]) { | ||
echo "Unexpected phrase retrieved:\n"; | ||
var_dump($phrase); | ||
} | ||
} | ||
|
||
dropTable($conn, $tableName); | ||
|
||
sqlsrv_free_stmt($stmt); | ||
sqlsrv_close($conn); | ||
|
||
echo "Done" . PHP_EOL; | ||
?> | ||
--EXPECT-- | ||
Done | ||
|