user warning: INSERT command denied to user I am not able to insert rows into a table even though I have granted permissions to the corresponding database user.

I am able to insert rows into the same table with the same user from an individual php application. But if I try to insert a row from drupal, I get the error message as follows.

user warning: INSERT command denied to user 'username'@'localhost' for table 'table_name'


I even tried changing the password of the database user and changed the settings.php of drupal to reflect the new password, but still I get the same error message. I am able to run the SELECT queries successfully but not INSERT queries. What might be the problem here? Any help is appreciated. Thanks.
That doesn't really make sense. Drupal is just a PHP application; if you're using exactly the same connection details in Drupal as you are in your stand-alone PHP application, and that works, it's only logical that your Drupal connection will work too.

You've obviously checked that the username and password are correct, but have you checked the Drupal is connecting to the server from localhost? That would be the only other possible difference. If Drupal is connecting from a remote machine then you'll need to grant specific privileges to the user for that specific location.

The easiest way to see what you've already got is to run a SHOW GRANTS query on the database in question. That will show you something like this:

Grants for username@localhost
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'username'@'localhost' IDENTIFIED BY PASSWORD '*xxxxxxxxxxxxx'


Plus a few more more rows more than likely.

Check through those rows to make doubly sure that there is a grant for INSERT for the database user AND the location that the Drupal website is connecting from.

EDIT

You could maybe get around the error using drupal_write_record():

$record = new stdClass;
$record-&gt;col1 = 'something';
$record-&gt;col2 = 'something';
$record-&gt;col3 = 'something';

drupal_write_record('table_name', $record);


But that really shouldn't make any difference