php-src/ext/mysqli/tests/061.phpt
Ulf Wendel 1855a57471 Introducing new environment variable:
MYSQL_TEST_SKIP_CONNECT_FAILURE = false

Every test that needs a working MySQL connection now includes
skipifconnectfailure.inc. If MYSQL_TEST_SKIP_CONNECT_FAILURE evaluates
to true skipifconnectfailure.inc tries to establish a database
connection. If no connection can be opened, the test will be skipped.
In case of MYSQL_TEST_SKIP_CONNECT_FAILURE = false (default) an no
connection, a test who cannot establish a connection will fail.

So, if you have a buggy configuration or a server that is sometimes
not available, you can now decide if you want the tests to ignore this
and skip the test or to fail (MYSQL_TEST_CONNECT_FAILURE = false, default).

Other, minor tweaks:
  042.phpt - whitespace
  067.phpt - parse error in SKIPIF section fixed
2007-08-09 08:41:12 +00:00

61 lines
1.8 KiB
PHP

--TEST--
local infile handler
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
function my_read($fp, &$buffer, $buflen, &$error) {
$buffer = strrev(fread($fp, $buflen));
return(strlen($buffer));
}
/*** test mysqli_connect 127.0.0.1 ***/
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
/* create temporary file */
$filename = dirname(__FILE__) . "061.csv";
$fp = fopen($filename, "w");
fwrite($fp, b"foo;bar");
fclose($fp);
if (!mysqli_query($link,"DROP TABLE IF EXISTS t_061"))
printf("Cannot drop table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!mysqli_query($link,"CREATE TABLE t_061 (c1 varchar(10), c2 varchar(10))"))
printf("Cannot create table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename))))
printf("Cannot load data: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
mysqli_set_local_infile_handler($link, "my_read");
if (!mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE t_061 FIELDS TERMINATED BY ';'", mysqli_real_escape_string($link, $filename))))
printf("Cannot load data using infile handler: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if ($result = mysqli_query($link, "SELECT c1,c2 FROM t_061")) {
while (($row = mysqli_fetch_row($result))) {
printf("%s-%s\n", $row[0], $row[1]);
printf("%s-%s\n", gettype($row[0]), gettype($row[1]));
}
mysqli_free_result($result);
}
mysqli_close($link);
unlink($filename);
print "done!";
?>
--EXPECT--
foo-bar
string-string
rab-oof
string-string
done!
--UEXPECTF--
foo-bar
unicode-unicode
rab-oof
unicode-unicode
done!