Hello,

I tried to load data from a csv file into mysql table.
I keep getting this error, but it does execute though.
Error: PHP Warning: mysql_query(): Unable to save result set in C:\Inetpub\wwwroot\index.php on line 62

Please help.

My code:

$insert_data="LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE test FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (date,value);";

mysql_query($insert_data,$con);

    Hmm...sort of sounds like mysql_query() does not realize that that statement will not return a result set. Afraid I don't know if there's a fix or not. The only time I ever did anything like that, I used exec() (or one of the related commands, I don't remember) and executed the mysql load via the command line.

      Since the mysql library is a bit outdated, have you tried using [man]mysqli[/man] instead?

        I am trying to use mysqli and I am getting this error:

        Call to undefined function mysqli_set_local_infile_handler() in C:\Inetpub\wwwroot\index.php

        I got this code from php.net:

        $db = mysqli_init();
        mysqli_real_connect($db, "localhost","root","","dbname");

        if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
        }
        else
        {
        echo "Connection established!";
        }

        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.csv' INTO TABLE t1");
        mysqli_set_local_infile_default($db);

          This has been resolved with the following code:

          $db = mysqli_init();
          mysqli_real_connect($db, "localhost","root","","dbname");

          mysqli_select_db($db, "dbname");

          $insert_data="LOAD DATA LOCAL INFILE 'input.csv' INTO TABLE testFIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (date,value);";

          mysqli_query($db,$insert_data);

            Write a Reply...