1--TEST-- 2local infile handler 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7if (!function_exists('mysqli_set_local_infile_handler')) 8 die("skip - function not available."); 9 10$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 11if (!$link) 12 die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); 13 14include_once("local_infile_tools.inc"); 15if ($msg = check_local_infile_support($link, $engine)) 16 die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error)); 17 18mysqli_close($link); 19?> 20--FILE-- 21<?php 22 require_once("connect.inc"); 23 24 function my_read($fp, &$buffer, $buflen, &$error) { 25 $buffer = strrev(fread($fp, $buflen)); 26 return(strlen($buffer)); 27 } 28 29 /*** test mysqli_connect 127.0.0.1 ***/ 30 $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket); 31 32 /* create temporary file */ 33 $filename = dirname(__FILE__) . "061.csv"; 34 $fp = fopen($filename, "w"); 35 fwrite($fp, b"foo;bar"); 36 fclose($fp); 37 38 if (!mysqli_query($link,"DROP TABLE IF EXISTS t_061")) 39 printf("Cannot drop table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 40 if (!mysqli_query($link,"CREATE TABLE t_061 (c1 varchar(10), c2 varchar(10))")) 41 printf("Cannot create table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 42 43 if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename)))) 44 printf("Cannot load data: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 45 46 mysqli_set_local_infile_handler($link, "my_read"); 47 if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename)))) 48 printf("Cannot load data using infile handler: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 49 50 if ($result = mysqli_query($link, "SELECT c1,c2 FROM t_061")) { 51 while (($row = mysqli_fetch_row($result))) { 52 printf("%s-%s\n", $row[0], $row[1]); 53 printf("%s-%s\n", gettype($row[0]), gettype($row[1])); 54 } 55 mysqli_free_result($result); 56 } 57 58 mysqli_close($link); 59 unlink($filename); 60 print "done!"; 61?> 62--CLEAN-- 63<?php 64require_once("connect.inc"); 65if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 66 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 67 68if (!mysqli_query($link, "DROP TABLE IF EXISTS t_061")) 69 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 70 71mysqli_close($link); 72?> 73--EXPECTF-- 74foo-bar 75%unicode|string%-%unicode|string% 76rab-oof 77%unicode|string%-%unicode|string% 78done! 79