Initial AppVeyor CI test build.
This commit is contained in:
parent
0762fa3353
commit
9f74ef7326
182
appveyor.yml
Normal file
182
appveyor.yml
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
version: '{branch}.{build}'
|
||||||
|
|
||||||
|
branches:
|
||||||
|
# whitelist
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- PHP-7.0
|
||||||
|
|
||||||
|
# blacklist
|
||||||
|
except:
|
||||||
|
- PHP-7.0-Linux
|
||||||
|
- PHP5
|
||||||
|
|
||||||
|
environment:
|
||||||
|
MSSQL_PASSWORD: Password12!
|
||||||
|
MSSQL_USERNAME: sa
|
||||||
|
PHP_DEPSVER: 7.0
|
||||||
|
PHP_SDK: c:\projects\php
|
||||||
|
matrix:
|
||||||
|
- BUILD_PLATFORM: x64
|
||||||
|
MSSQL_SERVERNAME: (local)\SQL2012SP1
|
||||||
|
SQL_INSTANCE: SQL2012SP1
|
||||||
|
PHP_VC: 14
|
||||||
|
PHP_MAJOR_VER: 7.0
|
||||||
|
PHP_MINOR_VER: latest
|
||||||
|
PHP_SDK_DIR: c:\projects\php\x64
|
||||||
|
PHP_INSTALL_DIR: c:\projects\php\x64\bin
|
||||||
|
PHP_ZTS: --disable-zts
|
||||||
|
platform: x64
|
||||||
|
# - BUILD_PLATFORM: x86
|
||||||
|
# MSSQL_SERVERNAME: (local)\SQL2014
|
||||||
|
# SQL_INSTANCE: SQL2014
|
||||||
|
# PHP_VC: 14
|
||||||
|
# PHP_MAJOR_VER: 7.0
|
||||||
|
# PHP_MINOR_VER: latest
|
||||||
|
# PHP_SDK_DIR: c:\projects\php\x86
|
||||||
|
# PHP_INSTALL_DIR: c:\projects\php\x86\bin
|
||||||
|
# platform: x86
|
||||||
|
# - BUILD_PLATFORM: x64
|
||||||
|
# MSSQL_SERVERNAME: (local)\SQL2016
|
||||||
|
# SQL_INSTANCE: SQL2016
|
||||||
|
# PHP_VC: 14
|
||||||
|
# PHP_MAJOR_VER: 7.1
|
||||||
|
# PHP_MINOR_VER: latest
|
||||||
|
# PHP_SDK_DIR: c:\projects\php\x64
|
||||||
|
# PHP_INSTALL_DIR: c:\projects\php\x64\bin
|
||||||
|
# platform: x64
|
||||||
|
# - BUILD_PLATFORM: x86
|
||||||
|
# MSSQL_SERVERNAME: (local)\SQL2008R2SP2
|
||||||
|
# SQL_INSTANCE: SQL2008R2SP2
|
||||||
|
# PHP_VC: 14
|
||||||
|
# PHP_MAJOR_VER: 7.1
|
||||||
|
# PHP_MINOR_VER: latest
|
||||||
|
# PHP_SDK_DIR: c:\projects\php\x86
|
||||||
|
# PHP_INSTALL_DIR: c:\projects\php\x86\bin
|
||||||
|
# PHP_ZTS: --disable-zts
|
||||||
|
# platform: x86
|
||||||
|
|
||||||
|
|
||||||
|
# PHP_MAJOR_VER is PHP major version to build (7.0, 7.1)
|
||||||
|
# PHP_MINOR_VER is PHP point release number (or latest for latest release)
|
||||||
|
# PHP_INSTALL_DIR is where the built PHP binaries go
|
||||||
|
# PHP_SDK_DIR is where PHP source is extracted to (e.g. PHP_SDK_DIR\php-7.0.14-src)
|
||||||
|
# PHP_SDK is where PHP sdk binary tools are extracted to
|
||||||
|
# PHP_VC is the Visual C++ version
|
||||||
|
# PHP_ZTS is defined to disable thread safe build
|
||||||
|
|
||||||
|
# Build worker image (VM template)
|
||||||
|
image: Visual Studio 2015
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
fast_finish: true
|
||||||
|
|
||||||
|
#services:
|
||||||
|
#- mssql2012sp1
|
||||||
|
|
||||||
|
# clone directory (or %APPVEYOR_BUILD_FOLDER%)
|
||||||
|
clone_folder: c:\projects\sqlphp
|
||||||
|
|
||||||
|
build:
|
||||||
|
parallel: true # enable MSBuild parallel builds
|
||||||
|
|
||||||
|
install:
|
||||||
|
- echo start SQL Server
|
||||||
|
# Based on http://www.appveyor.com/docs/services-databases
|
||||||
|
- ps: >-
|
||||||
|
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null ;
|
||||||
|
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null ;
|
||||||
|
|
||||||
|
$instanceName = $env:SQL_INSTANCE;
|
||||||
|
$uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ServerInstance[@Name='$instanceName']/ServerProtocol[@Name='Tcp']";
|
||||||
|
$wmi = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer');
|
||||||
|
$tcp = $wmi.GetSmoObject($uri);
|
||||||
|
$tcp.IsEnabled = $true;
|
||||||
|
$tcp.Alter();
|
||||||
|
Start-Service "MSSQL`$$instanceName";
|
||||||
|
|
||||||
|
Set-Service SQLBrowser -StartupType Manual;
|
||||||
|
Start-Service SQLBrowser;
|
||||||
|
- echo Set PHP version...
|
||||||
|
- appveyor DownloadFile http://windows.php.net/downloads/releases/sha1sum.txt
|
||||||
|
# determine latest PHP versions
|
||||||
|
- ps: >-
|
||||||
|
If ($env:PHP_MINOR_VER -Match "latest") {
|
||||||
|
$env:PHP_VERSION=type sha1sum.txt | where { $_ -match "php-($env:PHP_MAJOR_VER\.\d+)-src" } | foreach { $matches[1] } ;
|
||||||
|
} Else {
|
||||||
|
$env:PHP_VERSION=$env:PHP_MAJOR_VER + '.' + $env:PHP_MINOR_VER;
|
||||||
|
}
|
||||||
|
- echo Downloading PHP-SDK
|
||||||
|
- appveyor DownloadFile http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip
|
||||||
|
- move php-sdk-binary-tools-20110915.zip ..
|
||||||
|
- echo Downloading PHP source code [%PHP_VERSION%]
|
||||||
|
- ps: (new-object net.webclient).DownloadFile('http://windows.php.net/downloads/releases/php-' + ${env:PHP_VERSION} + '-src.zip', ${env:APPVEYOR_BUILD_FOLDER} + '\..\php.zip')
|
||||||
|
#- echo Downloading PHP deps [%PHP_DEPSVER%]
|
||||||
|
#- ps: (new-object net.webclient).DownloadFile('http://windows.php.net/downloads/php-sdk/deps-' + ${env:PHP_DEPSVER} + '-vc' + ${env:PHP_VC} + '-' + ${env:BUILD_PLATFORM} + '.7z', ${env:APPVEYOR_BUILD_FOLDER} + '\..\deps.7z')
|
||||||
|
- echo Downloading MSODBC 13
|
||||||
|
# 32-bit https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/X86/msodbcsql.msi
|
||||||
|
- ps: (new-object net.webclient).DownloadFile('https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/' + ${env:BUILD_PLATFORM} + '/msodbcsql.msi', 'msodbcsql.msi')
|
||||||
|
- ps: msiexec /i msodbcsql.msi /quiet /qn /norestart
|
||||||
|
- cd ..
|
||||||
|
- cd
|
||||||
|
- 7z x -y php-sdk-binary-tools-20110915.zip -o%PHP_SDK%
|
||||||
|
- 7z x -y php.zip -o%PHP_SDK_DIR%
|
||||||
|
- echo update SQL connection string
|
||||||
|
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:MSSQL_SERVERNAME} -replace "<YourStrong!Passw0rd>", ${env:MSSQL_PASSWORD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
|
||||||
|
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
|
||||||
|
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:MSSQL_SERVERNAME} -replace "<YourStrong!Passw0rd>", ${env:MSSQL_PASSWORD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
|
||||||
|
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- '"C:\\Program Files (x86)\\Microsoft Visual Studio %PHP_VC%.0\\VC\\vcvarsall.bat" %BUILD_PLATFORM%'
|
||||||
|
- Echo copy msphp code to ext folder
|
||||||
|
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv
|
||||||
|
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv\shared
|
||||||
|
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
|
||||||
|
- mkdir %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv\shared
|
||||||
|
- copy /Y %APPVEYOR_BUILD_FOLDER%\sqlsrv %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv
|
||||||
|
- copy /Y %APPVEYOR_BUILD_FOLDER%\shared %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\sqlsrv\shared
|
||||||
|
- copy /Y %APPVEYOR_BUILD_FOLDER%\shared %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv\shared
|
||||||
|
- copy /Y %APPVEYOR_BUILD_FOLDER%\pdo_sqlsrv %PHP_SDK_DIR%\php-%PHP_VERSION%-src\ext\pdo_sqlsrv
|
||||||
|
- cd %PHP_SDK_DIR%\php-%PHP_VERSION%-src
|
||||||
|
- cd
|
||||||
|
- dir
|
||||||
|
- '%PHP_SDK%\bin\phpsdk_setvars.bat'
|
||||||
|
- buildconf.bat
|
||||||
|
# only build CLI and MSSQL extensions
|
||||||
|
- configure.bat --disable-all %PHP_ZTS% --enable-cli --enable-sqlsrv=shared --with-pdo-sqlsrv=shared --enable-pdo=shared --with-prefix=%PHP_INSTALL_DIR%
|
||||||
|
- copy php.ini-development php.ini
|
||||||
|
- echo extension_dir=%PHP_INSTALL_DIR%\ext >> php.ini
|
||||||
|
- echo extension=php_sqlsrv.dll >> php.ini
|
||||||
|
- echo extension=php_pdo_sqlsrv.dll >> php.ini
|
||||||
|
- nmake
|
||||||
|
- nmake install
|
||||||
|
- Echo copy php.ini and run-tests.php from php source to install directory.
|
||||||
|
- copy php.ini %PHP_INSTALL_DIR%
|
||||||
|
- copy run-tests.php %PHP_INSTALL_DIR%
|
||||||
|
- dir %PHP_INSTALL_DIR%
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- cd %PHP_INSTALL_DIR%
|
||||||
|
- php --ini
|
||||||
|
- php -i
|
||||||
|
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\sqlsrv.log 2>&1
|
||||||
|
- type %APPVEYOR_BUILD_FOLDER%\test\sqlsrv.log
|
||||||
|
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv.log 2>&1
|
||||||
|
- type %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv.log
|
||||||
|
|
||||||
|
after_test:
|
||||||
|
- cd %APPVEYOR_BUILD_FOLDER%\test\
|
||||||
|
- python output.py
|
||||||
|
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult1.xml))
|
||||||
|
- ps: (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\nativeresult2.xml))
|
||||||
|
- ps: >-
|
||||||
|
[xml]$results = Get-Content nativeresult1.xml ;
|
||||||
|
[xml]$results2 = Get-Content nativeresult2.xml ;
|
||||||
|
$failure = $results.SelectSingleNode("//failure");
|
||||||
|
$failure2 = $results2.SelectSingleNode("//failure");
|
||||||
|
if ($failure -ne $null -Or $failure2 -ne $null)
|
||||||
|
{
|
||||||
|
$host.SetShouldExit(1);
|
||||||
|
Write-Host "Forcing build failure due to phpt unit test failure(s)";
|
||||||
|
}
|
133
test/output.py
Normal file
133
test/output.py
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
#########################################################################################
|
||||||
|
#
|
||||||
|
# Description:
|
||||||
|
# Requirement of python 3.4 to execute this script and required result log file are in the same location
|
||||||
|
# Run with command line without options required. Example: py output.py
|
||||||
|
# This script parse output of PHP Native Test
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#############################################################################################
|
||||||
|
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
import re
|
||||||
|
|
||||||
|
# This module returns either the number of test or the number of failed test
|
||||||
|
# depending on the argument you requested.
|
||||||
|
# Input: var - a single variable containing either "FAIL" or "TOTAL"
|
||||||
|
# Output: Returns a number of test/s or failed test/s
|
||||||
|
def returnCount(var):
|
||||||
|
with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f:
|
||||||
|
num = 0
|
||||||
|
failnum = 0
|
||||||
|
for line in f:
|
||||||
|
if "FAIL" in line or "PASS" in line:
|
||||||
|
if ".phpt" in line:
|
||||||
|
if "FAIL" in line:
|
||||||
|
failnum += 1
|
||||||
|
num += 1
|
||||||
|
if var == 'total':
|
||||||
|
return str(num)
|
||||||
|
else:
|
||||||
|
return str(failnum)
|
||||||
|
|
||||||
|
# This module prints the line that matches the expression.
|
||||||
|
# Input: inputStr - String that matches
|
||||||
|
# file - file name
|
||||||
|
# path - path of the file.
|
||||||
|
# Output: null
|
||||||
|
def readAndPrint(inputStr, file, path):
|
||||||
|
filn = open(path + os.sep + file).readlines()
|
||||||
|
for lines in filn:
|
||||||
|
if inputStr in lines:
|
||||||
|
print(lines)
|
||||||
|
|
||||||
|
# This module returns the test file name.
|
||||||
|
# Input: line - current line of the log file
|
||||||
|
# Output: Returns the filename.
|
||||||
|
def TestFilename(line):
|
||||||
|
terminateChar = os.sep
|
||||||
|
currentPos = 0
|
||||||
|
while True:
|
||||||
|
currentPos = currentPos - 1
|
||||||
|
line[currentPos]
|
||||||
|
if line[currentPos] == terminateChar:
|
||||||
|
break
|
||||||
|
file = line[currentPos+1:-1]
|
||||||
|
return file
|
||||||
|
|
||||||
|
def genXML(logfile,number):
|
||||||
|
# Generating the nativeresult.xml file.
|
||||||
|
file = open('nativeresult' + str(number) + '.xml','w')
|
||||||
|
file.write('<?xml version="1.0" encoding="UTF-8" ?>' + os.linesep)
|
||||||
|
file.write('<testsuite tests="' + returnCount('total') + '" failures="' + returnCount('fail') + '" name="Native Tests" >' + os.linesep)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
# Extract individual test results from the log file and
|
||||||
|
# enter it in the nativeresult.xml file.
|
||||||
|
|
||||||
|
with open(os.path.dirname(os.path.realpath(__file__)) + os.sep + logfile) as f:
|
||||||
|
num = 1
|
||||||
|
failnum = 0
|
||||||
|
for line in f:
|
||||||
|
file = open('nativeresult' + str(number) + '.xml','a')
|
||||||
|
if "FAIL" in line or "PASS" in line:
|
||||||
|
if ".phpt" in line:
|
||||||
|
|
||||||
|
file.write('\t<testcase name="')
|
||||||
|
if "FAIL" in line:
|
||||||
|
failnum += 1
|
||||||
|
result = re.search('FAIL(.*).', line)
|
||||||
|
file.write(TestFilename(str(result.group(1))) + '-' + str(num) + '">' + os.linesep)
|
||||||
|
stop_pos = result.group(1).find('[')
|
||||||
|
file.write('\t\t<failure message=" Failed in ' + str(result.group(1))[0:stop_pos] + '"/>' + os.linesep)
|
||||||
|
file.write('\t</testcase>' + os.linesep)
|
||||||
|
else:
|
||||||
|
result = re.search('PASS(.*).', line)
|
||||||
|
file.write(TestFilename(str(result.group(1))) + '-' + str(num) + '"/>' + os.linesep)
|
||||||
|
num += 1
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
file = open('nativeresult' + str(number) + '.xml','a')
|
||||||
|
file.write('</testsuite>' + os.linesep)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
def run():
|
||||||
|
num = 1
|
||||||
|
for f in os.listdir(os.path.dirname(os.path.realpath(__file__))):
|
||||||
|
if f.endswith("log"):
|
||||||
|
print('================================================')
|
||||||
|
print(os.path.splitext(f)[0])
|
||||||
|
readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
print('================================================')
|
||||||
|
logfile = f
|
||||||
|
genXML(logfile,num)
|
||||||
|
num = num + 1
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------- Main Function ---------------------------------------------------
|
||||||
|
|
||||||
|
# Display results on screen from result log file.
|
||||||
|
if __name__ == '__main__':
|
||||||
|
num = 1
|
||||||
|
for f in os.listdir(os.path.dirname(os.path.realpath(__file__))):
|
||||||
|
if f.endswith("log"):
|
||||||
|
print('================================================')
|
||||||
|
print("\n" + os.path.splitext(f)[0] + "\n")
|
||||||
|
readAndPrint('Number of tests :', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests skipped ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests warned ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests failed ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Expected fail ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
readAndPrint('Tests passed ', f, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
print('================================================')
|
||||||
|
logfile = f
|
||||||
|
genXML(logfile,num)
|
||||||
|
num = num + 1
|
||||||
|
|
16
test/pdo_sqlsrv/autonomous_setup.php
Normal file
16
test/pdo_sqlsrv/autonomous_setup.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
// Set SQL server + user + password
|
||||||
|
$serverName = getenv('MSSQL_SERVERNAME') ?: "localhost";
|
||||||
|
$username = getenv('MSSQL_USERNAME') ?: "sa";
|
||||||
|
$password = getenv('MSSQL_PASSWORD') ?: "<YourStrong!Passw0rd>";
|
||||||
|
|
||||||
|
|
||||||
|
// Generate unique DB name, example: php_20160817_1471475608267
|
||||||
|
$dbName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
|
||||||
|
|
||||||
|
// Generic table name example: php_20160817_1471475608267.dbo.php_firefly
|
||||||
|
$tableName = $dbName.".dbo.php_firefly";
|
||||||
|
|
||||||
|
// Connection options
|
||||||
|
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
|
||||||
|
?>
|
34
test/pdo_sqlsrv/pdo_002_connect_app.phpt
Normal file
34
test/pdo_sqlsrv/pdo_002_connect_app.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Connection option APP name unicode
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$appName = "APP_PoP_银河";
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
$conn = new PDO("sqlsrv:server=$serverName;APP=$appName","$username","$password");
|
||||||
|
|
||||||
|
// Query and Fetch
|
||||||
|
$query = "SELECT APP_NAME()";
|
||||||
|
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
while ( $row = $stmt->fetch(PDO::FETCH_NUM) ){
|
||||||
|
echo $row[0]."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ){
|
||||||
|
echo $row['']."\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the connection
|
||||||
|
$conn=null;
|
||||||
|
echo "Done"
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECTREGEX--
|
||||||
|
APP_PoP_银河
|
||||||
|
APP_PoP_银河
|
||||||
|
Done
|
55
test/pdo_sqlsrv/pdo_011_quote.phpt
Normal file
55
test/pdo_sqlsrv/pdo_011_quote.phpt
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
--TEST--
|
||||||
|
Insert with quoted parameters
|
||||||
|
--SKIPIF--
|
||||||
|
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
$conn = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
|
||||||
|
|
||||||
|
$param = 'a \' g';
|
||||||
|
$param2 = $conn->quote( $param );
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$conn->query("CREATE DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
// Create table
|
||||||
|
$query = "CREATE TABLE ".$tableName." (col1 VARCHAR(10), col2 VARCHAR(20))";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
if( $stmt === false ) { die(); }
|
||||||
|
|
||||||
|
// Inserd data
|
||||||
|
$query = "INSERT INTO $tableName VALUES( ?, '1' )";
|
||||||
|
$stmt = $conn->prepare( $query );
|
||||||
|
$stmt->execute(array($param));
|
||||||
|
|
||||||
|
// Inserd data
|
||||||
|
$query = "INSERT INTO $tableName VALUES( ?, ? )";
|
||||||
|
$stmt = $conn->prepare( $query );
|
||||||
|
$stmt->execute(array($param, $param2));
|
||||||
|
|
||||||
|
// Query
|
||||||
|
$query = "SELECT * FROM $tableName";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
|
||||||
|
print_r( $row['col1'] ." was inserted\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revert the inserts
|
||||||
|
$query = "delete from $tableName where col1 = ?";
|
||||||
|
$stmt = $conn->prepare( $query );
|
||||||
|
$stmt->execute(array($param));
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$conn->query("DROP DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
//free the statement and connection
|
||||||
|
$stmt=null;
|
||||||
|
$conn=null;
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
a ' g was inserted
|
||||||
|
a ' g was inserted
|
||||||
|
|
30
test/pdo_sqlsrv/pdo_012_bind_param.phpt
Normal file
30
test/pdo_sqlsrv/pdo_012_bind_param.phpt
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
--TEST--
|
||||||
|
uses an input/output parameter
|
||||||
|
--SKIPIF--
|
||||||
|
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$dbh = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$dbh->query("CREATE DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
$dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString");
|
||||||
|
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
|
||||||
|
$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?");
|
||||||
|
$string = "123456789";
|
||||||
|
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
|
||||||
|
$stmt->execute();
|
||||||
|
print "Result: ".$string."\n"; // Expect 987654321
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$dbh->query("DROP DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
//free the statement and connection
|
||||||
|
$stmt = null;
|
||||||
|
$dbh = null;
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Result: 987654321
|
60
test/pdo_sqlsrv/pdo_013_row_count.phpt
Normal file
60
test/pdo_sqlsrv/pdo_013_row_count.phpt
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
--TEST--
|
||||||
|
Number of rows in a result set
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$conn = new PDO( "sqlsrv:server=$serverName", "$username", "$password" );
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$conn->query("CREATE DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
// Create table
|
||||||
|
$stmt = $conn->query("CREATE TABLE ".$tableName." (c1 VARCHAR(32))");
|
||||||
|
$stmt=null;
|
||||||
|
|
||||||
|
// Insert data
|
||||||
|
$query = "INSERT INTO ".$tableName." VALUES ('Salmon'),('Butterfish'),('Cod'),('NULL'),('Crab')";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
$res[] = $stmt->rowCount();
|
||||||
|
|
||||||
|
// Update data
|
||||||
|
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='Cod'";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
$res[] = $stmt->rowCount();
|
||||||
|
|
||||||
|
// Update data
|
||||||
|
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='NULL'";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
$res[] = $stmt->rowCount();
|
||||||
|
|
||||||
|
// Update data
|
||||||
|
$query = "UPDATE ".$tableName." SET c1='Salmon' WHERE c1='NO_NAME'";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
$res[] = $stmt->rowCount();
|
||||||
|
|
||||||
|
// Update data
|
||||||
|
$query = "UPDATE ".$tableName." SET c1='N/A'";
|
||||||
|
$stmt = $conn->query($query);
|
||||||
|
$res[] = $stmt->rowCount();
|
||||||
|
|
||||||
|
print_r($res);
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$conn->query("DROP DATABASE ". $dbName) ?: die();
|
||||||
|
|
||||||
|
$stmt=null;
|
||||||
|
$conn=null;
|
||||||
|
print "Done"
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Array
|
||||||
|
(
|
||||||
|
[0] => 5
|
||||||
|
[1] => 1
|
||||||
|
[2] => 1
|
||||||
|
[3] => 0
|
||||||
|
[4] => 5
|
||||||
|
)
|
||||||
|
Done
|
16
test/sqlsrv/autonomous_setup.php
Normal file
16
test/sqlsrv/autonomous_setup.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
// Set SQL server + user + password
|
||||||
|
$serverName = getenv('MSSQL_SERVERNAME') ?: "localhost";
|
||||||
|
$username = getenv('MSSQL_USERNAME') ?: "sa";
|
||||||
|
$password = getenv('MSSQL_PASSWORD') ?: "<YourStrong!Passw0rd>";
|
||||||
|
|
||||||
|
|
||||||
|
// Generate unique DB name, example: php_20160817_1471475608267
|
||||||
|
$dbName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
|
||||||
|
|
||||||
|
// Generic table name example: php_20160817_1471475608267.dbo.php_firefly
|
||||||
|
$tableName = $dbName.".dbo.php_firefly";
|
||||||
|
|
||||||
|
// Connection options
|
||||||
|
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
|
||||||
|
?>
|
21
test/sqlsrv/srv_001.phpt
Normal file
21
test/sqlsrv/srv_001.phpt
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
--TEST--
|
||||||
|
Connect to the default database with credentials
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password" );
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo );
|
||||||
|
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
Done
|
21
test/sqlsrv/srv_002.phpt
Normal file
21
test/sqlsrv/srv_002.phpt
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
--TEST--
|
||||||
|
Connect with options
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array("Database"=>"master", "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
Done
|
52
test/sqlsrv/srv_012_sqlsrv_fetch_array.phpt
Normal file
52
test/sqlsrv/srv_012_sqlsrv_fetch_array.phpt
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
--TEST--
|
||||||
|
sqlsrv_fetch_array() using a scrollable cursor
|
||||||
|
--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 VARCHAR(10))";
|
||||||
|
$stmt = sqlsrv_query($conn, $query);
|
||||||
|
|
||||||
|
$query = "INSERT INTO $tableName VALUES ('1998.1'),('-2004'),('2016'),('4.2EUR')";
|
||||||
|
$stmt = sqlsrv_query($conn, $query) ?: die( print_r( sqlsrv_errors(), true) );
|
||||||
|
|
||||||
|
// Fetch data
|
||||||
|
$query = "SELECT ID FROM $tableName";
|
||||||
|
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"))
|
||||||
|
?: die( print_r(sqlsrv_errors(), true));
|
||||||
|
|
||||||
|
// Fetch first row
|
||||||
|
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_NEXT);
|
||||||
|
echo $row['ID']."\n";
|
||||||
|
|
||||||
|
// Fetch third row
|
||||||
|
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_ABSOLUTE,2);
|
||||||
|
echo $row['ID']."\n";
|
||||||
|
|
||||||
|
// Fetch last row
|
||||||
|
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_LAST);
|
||||||
|
echo $row['ID']."\n";
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
|
||||||
|
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done"
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
1998.1
|
||||||
|
2016
|
||||||
|
4.2EUR
|
||||||
|
Done
|
53
test/sqlsrv/srv_014_sqlsrv_get_field.phpt
Normal file
53
test/sqlsrv/srv_014_sqlsrv_get_field.phpt
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
--TEST--
|
||||||
|
sqlsrv_get_field() using SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY)
|
||||||
|
--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 VARCHAR(10))";
|
||||||
|
$stmt = sqlsrv_query($conn, $query);
|
||||||
|
|
||||||
|
$query = "INSERT INTO ".$tableName." VALUES ('1998.1'),('-2004.2436'),('4.2EUR')";
|
||||||
|
$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_BINARY));
|
||||||
|
var_dump($field);
|
||||||
|
|
||||||
|
while(!feof($field))
|
||||||
|
{
|
||||||
|
echo fread($field, 100)."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
|
||||||
|
|
||||||
|
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.2EUR
|
||||||
|
Done
|
97
test/sqlsrv/srv_031_sqlsrv_field_metadata.phpt
Normal file
97
test/sqlsrv/srv_031_sqlsrv_field_metadata.phpt
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
--TEST--
|
||||||
|
sqlsrv_field_metadata() VARCHAR(n), NVARCHAR(n), INT
|
||||||
|
--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
|
||||||
|
$stmt = sqlsrv_query($conn, "create table ".$tableName." (FirstName VARCHAR(10), LastName NVARCHAR(20), Age INT)");
|
||||||
|
if( $stmt === false ) { die( print_r( sqlsrv_errors(), true )); }
|
||||||
|
sqlsrv_free_stmt( $stmt);
|
||||||
|
|
||||||
|
// Insert data
|
||||||
|
$sql = "INSERT INTO ".$tableName." VALUES ('John', 'Doe', 30)";
|
||||||
|
$stmt = sqlsrv_query( $conn, $sql);
|
||||||
|
sqlsrv_free_stmt( $stmt);
|
||||||
|
|
||||||
|
// Insert data
|
||||||
|
$sql = "INSERT INTO ".$tableName." VALUES ('Nhoj', N'Eoduard', -3),('Vi Lo', N'N/A', 1987)";
|
||||||
|
$stmt = sqlsrv_query($conn, $sql);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
// Prepare the statement
|
||||||
|
$query = "SELECT FirstName, LastName, Age FROM ".$tableName;
|
||||||
|
$stmt = sqlsrv_prepare($conn, $query);
|
||||||
|
|
||||||
|
// Get field metadata
|
||||||
|
foreach( sqlsrv_field_metadata( $stmt) as $fieldMetadata)
|
||||||
|
$res[] = $fieldMetadata;
|
||||||
|
|
||||||
|
var_dump($res);
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
|
||||||
|
|
||||||
|
sqlsrv_free_stmt( $stmt);
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
array(3) {
|
||||||
|
[0]=>
|
||||||
|
array(6) {
|
||||||
|
["Name"]=>
|
||||||
|
string(9) "FirstName"
|
||||||
|
["Type"]=>
|
||||||
|
int(12)
|
||||||
|
["Size"]=>
|
||||||
|
int(10)
|
||||||
|
["Precision"]=>
|
||||||
|
NULL
|
||||||
|
["Scale"]=>
|
||||||
|
NULL
|
||||||
|
["Nullable"]=>
|
||||||
|
int(1)
|
||||||
|
}
|
||||||
|
[1]=>
|
||||||
|
array(6) {
|
||||||
|
["Name"]=>
|
||||||
|
string(8) "LastName"
|
||||||
|
["Type"]=>
|
||||||
|
int(-9)
|
||||||
|
["Size"]=>
|
||||||
|
int(20)
|
||||||
|
["Precision"]=>
|
||||||
|
NULL
|
||||||
|
["Scale"]=>
|
||||||
|
NULL
|
||||||
|
["Nullable"]=>
|
||||||
|
int(1)
|
||||||
|
}
|
||||||
|
[2]=>
|
||||||
|
array(6) {
|
||||||
|
["Name"]=>
|
||||||
|
string(3) "Age"
|
||||||
|
["Type"]=>
|
||||||
|
int(4)
|
||||||
|
["Size"]=>
|
||||||
|
NULL
|
||||||
|
["Precision"]=>
|
||||||
|
int(10)
|
||||||
|
["Scale"]=>
|
||||||
|
NULL
|
||||||
|
["Nullable"]=>
|
||||||
|
int(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Done
|
41
test/sqlsrv/srv_073_database.phpt
Normal file
41
test/sqlsrv/srv_073_database.phpt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
--TEST--
|
||||||
|
PHPT Create/drop database
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "php_uniqueDB01";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
if($stmt === false){ die( print_r( sqlsrv_errors(), true )); }
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
if($stmt === false){ die( print_r( sqlsrv_errors(), true )); }
|
||||||
|
echo "DATABASE CREATED\n";
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbUniqueName);
|
||||||
|
if($stmt === false){ die( print_r( sqlsrv_errors(), true )); }
|
||||||
|
echo "DATABASE DROPPED\n";
|
||||||
|
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
DATABASE CREATED
|
||||||
|
DATABASE DROPPED
|
||||||
|
Done
|
62
test/sqlsrv/srv_074_create_existing_database.phpt
Normal file
62
test/sqlsrv/srv_074_create_existing_database.phpt
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
--TEST--
|
||||||
|
Create database that already exists
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "uniqueDB01";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
|
||||||
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database that already exists
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
var_dump($stmt);
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
$res = array_values(sqlsrv_errors());
|
||||||
|
var_dump($res[0]['SQLSTATE']);
|
||||||
|
var_dump($res[0][1]);
|
||||||
|
// var_dump($res[0][2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
string(5) "42000"
|
||||||
|
int(1801)
|
||||||
|
Done
|
62
test/sqlsrv/srv_074_database.phpt
Normal file
62
test/sqlsrv/srv_074_database.phpt
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
--TEST--
|
||||||
|
PHPT Create database that already exists
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "uniqueDB01";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
|
||||||
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database that already exists
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
var_dump($stmt);
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
$res = array_values(sqlsrv_errors());
|
||||||
|
var_dump($res[0]['SQLSTATE']);
|
||||||
|
var_dump($res[0][1]);
|
||||||
|
// var_dump($res[0][2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
string(5) "42000"
|
||||||
|
int(1801)
|
||||||
|
Done
|
61
test/sqlsrv/srv_074_database_wide_string.phpt
Normal file
61
test/sqlsrv/srv_074_database_wide_string.phpt
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
--TEST--
|
||||||
|
PHPT Create database that already exists
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "uniqueDB01";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
|
||||||
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CREATE database that already exists
|
||||||
|
$stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
|
||||||
|
var_dump($stmt);
|
||||||
|
if( $stmt === false)
|
||||||
|
{
|
||||||
|
$res = array_values(sqlsrv_errors());
|
||||||
|
var_dump($res[0]['SQLSTATE']);
|
||||||
|
var_dump($res[0][1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// DROP database
|
||||||
|
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
string(5) "42000"
|
||||||
|
int(1801)
|
||||||
|
Done
|
44
test/sqlsrv/srv_075_database.phpt
Normal file
44
test/sqlsrv/srv_075_database.phpt
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
--TEST--
|
||||||
|
PHPT Drop missing database
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "uniqueDB01";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
// DROP missing database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbUniqueName);
|
||||||
|
var_dump($stmt);
|
||||||
|
if( $stmt === false )
|
||||||
|
{
|
||||||
|
$res = array_values(sqlsrv_errors());
|
||||||
|
var_dump($res[0]['code']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%-20s\n","ERROR: DROP missing database MUST return bool(false)");
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
int(3701)
|
||||||
|
Done
|
49
test/sqlsrv/srv_075_database_wide_string.phpt
Normal file
49
test/sqlsrv/srv_075_database_wide_string.phpt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
--TEST--
|
||||||
|
PHPT Drop missing database
|
||||||
|
--SKIPIF--
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("autonomous_setup.php");
|
||||||
|
|
||||||
|
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password", "CharacterSet" => 'UTF-8');
|
||||||
|
$conn = sqlsrv_connect( $serverName, $connectionInfo);
|
||||||
|
|
||||||
|
// Check if connected
|
||||||
|
if( !$conn ) {
|
||||||
|
echo "Connection could not be established.\n";
|
||||||
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set database name
|
||||||
|
$dbUniqueName = "uniqueDB01_银河系";
|
||||||
|
|
||||||
|
// DROP database if exists
|
||||||
|
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
|
||||||
|
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
// DROP missing database
|
||||||
|
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbUniqueName);
|
||||||
|
var_dump($stmt);
|
||||||
|
if( $stmt === false )
|
||||||
|
{
|
||||||
|
$res = array_values(sqlsrv_errors());
|
||||||
|
var_dump($res[0]['SQLSTATE']);
|
||||||
|
var_dump($res[0][1]);
|
||||||
|
var_dump($res[0][2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%-20s\n","ERROR: DROP missing database MUST return bool(false)");
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
print "Done";
|
||||||
|
?>
|
||||||
|
|
||||||
|
--EXPECT--
|
||||||
|
bool(false)
|
||||||
|
string(5) "42S02"
|
||||||
|
int(3701)
|
||||||
|
string(159) "[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot drop the database 'uniqueDB01_银河系', because it does not exist or you do not have permission."
|
||||||
|
Done
|
Loading…
Reference in a new issue