xref: /PHP-7.2/ext/pdo_dblib/tests/config.inc (revision 7f6387b5)
1<?php
2
3function get_tds_version() {
4	global $dsn;
5
6	$dsn_parts = explode(':', $dsn, 2);
7	if ($dsn_parts[0] == 'dblib') { // uri is an option, which we'll ignore
8		foreach (explode(';', $dsn_parts[1]) as $arg) {
9			$arg = explode('=', $arg);
10			if ($arg[0] == 'version') {
11				return $arg[1];
12			}
13		}
14	}
15
16	return null;
17}
18
19// bug #72969 reflects a bug with FreeTDS, not with pdo_dblib
20// this function will version detect so the relevant tests can XFAILIF
21function driver_supports_batch_statements_without_select($db) {
22	$version = $db->getAttribute(PDO::DBLIB_ATTR_VERSION);
23
24	// assume driver doesn't have this bug if not using FreeTDS
25	if (!strstartswith($version, 'freetds ')) {
26		return true;
27	}
28
29	// hasn't made it to numbered release yet
30	if (!strstartswith($version, 'freetds v1.1.dev.')) {
31		return false;
32	}
33
34	// fc820490336c50d5c175d2a15327383256add4c9 was committed on the 5th
35	return intval(substr($version, -8)) >= 20161206;
36}
37
38function strstartswith($haystack, $needle) {
39	return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
40}
41
42if (false !== getenv('PDO_DBLIB_TEST_DSN')) {
43	$dsn = getenv('PDO_DBLIB_TEST_DSN');
44} else {
45	$dsn = 'dblib:host=localhost;dbname=test';
46}
47
48if (false !== getenv('PDO_DBLIB_TEST_USER')) {
49	$user = getenv('PDO_DBLIB_TEST_USER');
50} else {
51	$user = 'php';
52}
53
54if (false !== getenv('PDO_DBLIB_TEST_PASS')) {
55	$pass = getenv('PDO_DBLIB_TEST_PASS');
56} else {
57	$pass = 'password';
58}
59
60try {
61	$db = new PDO($dsn, $user, $pass);
62	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
63	$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
64} catch (PDOException $e) {
65	die('skip ' . $e->getMessage());
66}
67
68?>
69