0

Query runs fine when executed on DB directly, but when executed using PHP it fails.

SELECT  count(A.age),LEFT(C.name, 10) FROM game A  INNER JOIN `dixit` C ON (A.roll=C.roll) WHERE LEFT(C.added, 10)>='09-05-2013' group by LEFT(C.added, 10) INTO OUTFILE '/tmp/total.txt';

In PHP:

$query_t = "
    SELECT  count(A.age),LEFT(C.name, 10) 
    FROM game A  
    INNER JOIN `dixit` C ON (A.roll=C.roll) 
    WHERE LEFT(C.added, 10)>='09-05-2013' 
    GROUP BY LEFT(C.added, 10) 
    INTO OUTFILE '/tmp/total.txt'
";

mysql_query($query_t) or die ("query failed");
2
  • 6
    For starters, use mysql_error() instead of "query failed" Commented Sep 13, 2013 at 22:10
  • Might not be the query then. Make sure you're connecting to the DB successfully first. Commented Sep 13, 2013 at 22:13

1 Answer 1

1

The problem is you can't use INTO OUTFILE statement in PHP. MySQL docs says:

The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some other host than the server host, you normally cannot use SELECT ... INTO OUTFILE since there is no way to write a path to the file relative to the server host's file system.

I think, their suggestion below can help you.

However, if the MySQL client software is installed on the remote machine, you can instead use a client command such as mysql -e "SELECT ..." > file_name to generate the file on the client host.

If not, maybe there will be other way, but I'm sure you need to dig into that way.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.