Annotation of embedaddon/php/ext/mysqli/tests/061.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: local infile handler
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifconnectfailure.inc');
! 7: if (!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);
! 11: if (!$link)
! 12: die(sprintf("skip Can't connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
! 13:
! 14: include_once("local_infile_tools.inc");
! 15: if ($msg = check_local_infile_support($link, $engine))
! 16: die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error));
! 17:
! 18: mysqli_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
! 64: require_once("connect.inc");
! 65: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
! 66: printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
! 67:
! 68: if (!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:
! 71: mysqli_close($link);
! 72: ?>
! 73: --EXPECTF--
! 74: foo-bar
! 75: %unicode|string%-%unicode|string%
! 76: rab-oof
! 77: %unicode|string%-%unicode|string%
! 78: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>