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