Check that sqlsrv and pdo_sqlsrv PHP extensions actually work

Test: sqlsrv, pdo_sqlsrv
pull/265/head
Michele Locati 2021-01-20 09:37:47 +01:00
parent e05b0cdc0f
commit 66fa5885ac
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
2 changed files with 67 additions and 0 deletions

28
scripts/tests/pdo_sqlsrv Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env php
<?php
error_reporting(-1);
set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
$msg = "Error {$errno}: {$errstr}\n";
if ($errfile) {
$msg .= "File: {$errfile}\n";
if ($errline) {
$msg .= "Line: {$errline}\n";
}
}
fwrite(STDERR, $msg);
exit(1);
},
-1
);
try {
new PDO('sqlsrv:server=localhost; Authentication=SqlPassword; ConnectRetryCount=0; Database=example; LoginTimeout=1', 'userName', 'password');
} catch (PDOException $x) {
if (stripos($x->getMessage(), 'This extension requires the Microsoft ODBC Driver for SQL Server') !== false) {
fwrite(STDERR, trim($x->getMessage() . "\n"));
exit(1);
}
}

39
scripts/tests/sqlsrv Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php
error_reporting(-1);
set_error_handler(
static function ($errno, $errstr, $errfile, $errline) {
$msg = "Error {$errno}: {$errstr}\n";
if ($errfile) {
$msg .= "File: {$errfile}\n";
if ($errline) {
$msg .= "Line: {$errline}\n";
}
}
fwrite(STDERR, $msg);
exit(1);
},
-1
);
sqlsrv_connect(
'localhost, 50000',
[
'Authentication' => 'SqlPassword',
'ConnectRetryCount' => 0,
'Database' => 'example',
'LoginTimeout' => 1, // string for PDO_SQLSRV
'UID' => 'userName', // not for PDO_SQLSRV
'PWD' => 'password',
]
);
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
if (is_array($errors)) {
foreach ($errors as $error) {
if (isset($error['message']) && stripos($error['message'], 'This extension requires the Microsoft ODBC Driver for SQL Server') !== false) {
fwrite(STDERR, trim($error['message']) . "\n");
}
}
}