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