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