Problem: The MySQL variable tmpdir is set to a directory that cannot be written to when using PHP to access MySQL.
To verify this, enter MySQL at the command line and type show variables;
You'll get a long list and one of them will read: tmpdir = /somedir/
(whatever your setting is.)