update : 2015.11.03
php.shukuma.com

검색:
 
 
Set callback function for LOAD DATA LOCAL INFILE command

mysqli::set_local_infile_handler

mysqli_set_local_infile_handler

(PHP 5)

mysqli::set_local_infile_handler -- mysqli_set_local_infile_handlerSet callback function for LOAD DATA LOCAL INFILE command

설명

객체 기반 형식

bool mysqli::set_local_infile_handler ( mysqli $link , callable $read_func )

절차식 형식

bool mysqli_set_local_infile_handler ( mysqli $link , callable $read_func )

Set callback function for LOAD DATA LOCAL INFILE command

The callbacks task is to read input from the file specified in the LOAD DATA LOCAL INFILE and to reformat it into the format understood by LOAD DATA INFILE.

The returned data needs to match the format specified in the LOAD DATA

인수

link

순차 형식 전용: mysqli_connect()mysqli_init()가 반환한 연결 식별자.

read_func

A callback function or object method taking the following parameters:

stream

A PHP stream associated with the SQL commands INFILE

&buffer

A string buffer to store the rewritten input into

buflen

The maximum number of characters to be stored in the buffer

&errormsg

If an error occurs you can store an error message in here

The callback function should return the number of characters stored in the buffer or a negative value if an error occurred.

반환값

성공 시 TRUE를, 실패 시 FALSE를 반환합니다.

예제

Example #1 mysqli::set_local_infile_handler() example

객체 기반 형식

<?php
  $db 
mysqli_init();
  
$db->real_connect("localhost","root","","test");

  function 
callme($stream, &$buffer$buflen, &$errmsg)
  {
    
$buffer fgets($stream);

    echo 
$buffer;

    
// convert to upper case and replace "," delimiter with [TAB]
    
$buffer strtoupper(str_replace(",""\t"$buffer));

    return 
strlen($buffer);
  }


  echo 
"Input:\n";

  
$db->set_local_infile_handler("callme");
  
$db->query("LOAD DATA LOCAL INFILE 'input.txt' INTO TABLE t1");
  
$db->set_local_infile_default();

  
$res $db->query("SELECT * FROM t1");

  echo 
"\nResult:\n";
  while (
$row $res->fetch_assoc()) {
    echo 
join(","$row)."\n";
  }
?>

절차식 형식

<?php
  $db 
mysqli_init();
  
mysqli_real_connect($db"localhost","root","","test");

  function 
callme($stream, &$buffer$buflen, &$errmsg)
  {
    
$buffer fgets($stream);

    echo 
$buffer;

    
// convert to upper case and replace "," delimiter with [TAB]
    
$buffer strtoupper(str_replace(",""\t"$buffer));

    return 
strlen($buffer);
  }


  echo 
"Input:\n";

  
mysqli_set_local_infile_handler($db"callme");
  
mysqli_query($db"LOAD DATA LOCAL INFILE 'input.txt' INTO TABLE t1");
  
mysqli_set_local_infile_default($db);

  
$res mysqli_query($db"SELECT * FROM t1");


  echo 
"\nResult:\n";
  while (
$row mysqli_fetch_assoc($res)) {
    echo 
join(","$row)."\n";
  }
?>

위 예제들의 출력:

Input:
23,foo
42,bar

Output:
23,FOO
42,BAR

참고