1--TEST--
2PDO::ATTR_SERVER_VERSION
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9$db = MySQLPDOTest::factory();
10?>
11--FILE--
12<?php
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $db = MySQLPDOTest::factory();
15
16    assert(('' == $db->errorCode()) || ('00000' == $db->errorCode()));
17
18    $version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
19    if ('' == $version)
20        printf("[001] Server version must not be empty\n");
21
22    // Ideally the server version would be an integer - as documented but BC break!
23    // If its a version string it should be of the format \d+\.\d+\.\d+.*
24
25    if (is_string($version)) {
26        // Its not an int like documented but a string - maybe for BC reasons...
27        if (!preg_match('/(\d+)\.(\d+)\.(\d+)(.*)/', $version, $matches))
28            printf("[002] Client version string seems wrong, got '%s'\n", $version);
29        else {
30            // Difficult to define any meaningful constraints
31            // A possible better check would be calling mysqli_get_server_version() and
32            // comparing what we get. However, mysqli_get_server_version() needs a mysqli handle
33            // for which in turn one needs to parse the PDO test environment variables
34            // for connection parameter...
35            if ($matches[1] < 3)
36                printf("[003] Strange major version: '%s'. Should be more than 3\n", $matches[1]);
37            if ($matches[2] < 0)
38                printf("[004] Minor version should be at least 0, got '%s'\n", $matches[2]);
39            if ($matches[3] < 0)
40                printf("[005] Sub version should be at least 0, got '%s'\n", $matches[2]);
41        }
42    } else if (is_int($version)) {
43        // Lets accept also int if it follows the rules from the original MYSQL C API
44        $major = floor($version / 10000);
45        $minor = floor(($version - ($main * 10000)) / 100);
46        $sub = $version - ($main * 10000) - ($minor * 100);
47        if ($major < 3)
48            printf("[006] Strange major version: '%s'. Should be more than 3\n", $major);
49        if ($minor < 0)
50            printf("[007] Minor version should be at least 0, got '%s'\n", $minor);
51        if ($sub < 0)
52            printf("[008] Sub version should be at least 0, got '%s'\n", $sub);
53    }
54
55    // Read-only?
56    if (false !== $db->setAttribute(PDO::ATTR_CLIENT_VERSION, '1.0'))
57        printf("[009] Wonderful, I can change the client version!\n");
58
59    $new_version = $db->getAttribute(PDO::ATTR_SERVER_VERSION);
60    if ($new_version !== $version)
61        printf("[010] Did we change it from '%s' to '%s'?\n", $version, $new_version);
62
63    print "done!";
64?>
65--EXPECT--
66done!
67