1--TEST--
2mysqli_options()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    /* see mysqli.c for details */
11    require_once("connect.inc");
12
13    if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)))
14        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
15            $host, $user, $db, $port, $socket);
16
17    /* TODO: test more options */
18    if (!mysqli_query($link, "DROP TABLE IF EXISTS test") ||
19        !mysqli_query($link, sprintf("CREATE TABLE test(id INT) ENGINE = %s\n", $engine)) ||
20        !mysqli_query($link, "INSERT INTO test(id) VALUES (1)"))
21        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    if (!$res = mysqli_query($link, "SELECT COUNT(id) AS _num_rows FROM test"))
24        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
25
26    $row = mysqli_fetch_assoc($res);
27    mysqli_free_result($res);
28
29    if ($row['_num_rows'] != 1)
30        printf("[003] Expecting 1 got %s\n", $row['_num_rows']);
31
32    mysqli_close($link);
33
34    $link = mysqli_init();
35    if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(id) VALUES (2)"))
36        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
37
38    if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))
39        printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
40            $host, $user, $db, $port, $socket);
41
42    if (!$res = mysqli_query($link, "SELECT COUNT(id) AS _num_rows FROM test"))
43        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
44
45    $row = mysqli_fetch_assoc($res);
46    mysqli_free_result($res);
47
48    if ($row['_num_rows'] != 2)
49        printf("[007] Expecting 1 got %s\n", $row['_num_rows']);
50
51    mysqli_close($link);
52
53    $link = mysqli_init();
54    if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(i_do_no_exist) VALUES (2)"))
55        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56
57    mysqli_close($link);
58
59    $link = mysqli_init();
60    if (true !== mysqli_options($link, MYSQLI_INIT_COMMAND, "INSERT INTO test(i_do_no_exist) VALUES (2)"))
61        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62
63    if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))
64        printf("[010] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
65            $host, $user, $db, $port, $socket);
66
67    print "done!";
68?>
69--CLEAN--
70<?php
71    require_once("clean_table.inc");
72?>
73--EXPECTF--
74Warning: mysqli_real_connect(): (%s/%d): %s in %s on line %d
75[010] Cannot connect to the server using %s
76done!
77