MySQL LOAD_FILE returning NULL

Simon picture Simon · Jan 5, 2011 · Viewed 15.2k times · Source

I'm doing this SELECT LOAD_FILE("/home/user/domains/example.com/public_html/robots.txt") AS tmp FROM tmpTable but it returns NULL. How can I check if this is because I haven't got the FILE privilege or if it's something else? MySQL won't give an error. (I'm using PHP)

Anyone that has experience with LOAD_FILE, tell me about that function:)

<?php
$result = mysql_query('SELECT LOAD_FILE("/home/user/domains/example.com/public_html/robots.txt") AS tmp FROM tmpTable') or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
var_dump( $row['tmp'] );
}

Answer

Daniel Pecos picture Daniel Pecos · Dec 29, 2012

A really ugly workaround can be found here:

http://angkatbahu.blogspot.com.es/2011/03/mysql-loadfile-function-in-ubuntu-it_12.html

If you put the files you want to load in /var/lib/mysql/all_images directory, it works!

Tested in ubuntu 12.10 (and no, chomd'ing files to mysql user, didn't work)